Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在页面加载时强制JS加载_Javascript_Geolocation_Reload - Fatal编程技术网

Javascript 在页面加载时强制JS加载

Javascript 在页面加载时强制JS加载,javascript,geolocation,reload,Javascript,Geolocation,Reload,我正在尝试使用Geobytes加载页面 <html> <head> </head> <body style="background: transparent; border: none;"> <script src="http://gd.geobytes.com/Gd?pages=US&ext=html&after=-1" language="Javascript"></script><script l

我正在尝试使用Geobytes加载页面

<html>
<head>
</head>
<body style="background: transparent; border: none;">
<script src="http://gd.geobytes.com/Gd?pages=US&ext=html&after=-1" language="Javascript"></script><script language="javascript">// <![CDATA[
if(typeof(sGeobytesLocationCode)!="undefined"&&sGeobytesLocationCode.indexOf('US')==0)
{
    document.write("<META HTTP-EQUIV='Refresh' CONTENT='06; URL=http://www.example.com'>");
}
// ]]></script>
</body>
</html>

// 

谁能给我指出正确的方向吗?我可以让函数onload工作,因为它是一个弹出窗口。

当页面上的所有内容(包括DOM(文档对象模型)内容、异步javascript、帧和图像)完全加载时,将触发
加载事件

当初始HTML文档已完全加载和解析时,也可以使用
DOMContentLoaded
事件(更快),而无需等待样式表、图像和子帧完成加载

<script>
// For legacy browsers use this instead: window.onload = function()
window.addEventListener('load', function () {

  if(typeof(sGeobytesLocationCode)!="undefined" && sGeobytesLocationCode.indexOf('US')==0)
  {
    document.write("<META HTTP-EQUIV='Refresh' CONTENT='06; URL=http://www.example.com'>");
  }

}, false);
</script>

//对于旧式浏览器,请改用此选项:window.onload=function()
window.addEventListener('load',函数(){
if(typeof(sGeobytesLocationCode)!=“undefined”&&sGeobytesLocationCode.indexOf('US')==0)
{
文件。填写(“”);
}
},假);

加载后的函数(){
if(typeof(sGeobytesLocationCode)!=“undefined”&&sGeobytesLocationCode.indexOf('US')==0)
{
文件。填写(“”);
}                
}

正确答案…

这个问题有点误导人,似乎让人们走上了错误的道路。不需要文档onload处理程序。下面的代码在没有代码的情况下按预期工作

这是一个例子,我从网站和返工。meta标记重定向部分也可以工作,但是我在这里发布的代码中禁用了它。代码的目的是自动将用户重定向到特定于国家/地区的页面

该网站有许多免费的web服务,值得一看

运行要测试的代码段:

//禁用:通过插入元标记将访客从美国重定向到www.whitehouse.gov
if(typeof(sGeobytesLocationCode)!=“undefined”&&sGeobytesLocationCode.indexOf('US')==0){
//文件。填写(“”);
}

document.write('sGeobytesLocationCode='+sGeobytesLocationCode);

*不能(对不起,输入错误)顺便说一句,您可以编辑问题而不是评论。不需要onload功能。请看下面我的答案。你说得很对,罗伯特。出现错误是因为我试图添加函数加载。谢谢你的回答。如果我能,我会投赞成票。要评论Geobytes,这是一项很棒的服务。我主要使用GeoLocate,但对于这个特定的实例,PHP不起作用。谢谢你的帮助!
<html>
    <head>        
        <script src="http://gd.geobytes.com/Gd?pages=US&ext=html&after=-1" type="text/javascript"></script>
        <script>

            function after_load() {
                if (typeof (sGeobytesLocationCode) != "undefined" && sGeobytesLocationCode.indexOf('US') == 0)
                {
                    document.write("<META HTTP-EQUIV='Refresh' CONTENT='06; URL=http://www.example.com'>");
                }                
            }

        </script>
    </head>
    <body onload="after_load()" style="background: transparent; border: none;">
    </body>
</html>