强制JS加载页面加载

时间:2015-05-18 20:33:18

标签: 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 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工作,因为它是一个弹出窗口。

3 个答案:

答案 0 :(得分:0)

当页面上的所有内容完全加载时,<head> <!-- … --> <link href="http://domain.com/" hreflang="x-default" rel="alternate"> <link href="http://domain.com/?hl=en" hreflang="en" rel="alternate"> <link href="http://domain.com/?hl=es" hreflang="es" rel="alternate"> </head> 事件将触发,包括DOM(文档对象模型)内容,异步javascript,框架和图像。

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

DOMContentLoaded

答案 1 :(得分:0)

<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>

答案 2 :(得分:0)

正确答案......

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

这是我从GeoBytes网站上获取并重新编写的示例。元标记重定向部分也有效,但我已在此处发布的代码中将其禁用。该代码的目的是自动将用户重定向到特定国家/地区的页面。

GeoBytes网站有许多免费的网络服务,值得一看。

运行代码段进行测试:

&#13;
&#13;
<html>
<head>
<script src="http://gd.geobytes.com/Gd?pages=US&ext=html&after=-1" type="text/javascript"></script>
<script type="text/javascript">
// DISABLED: Redirect vistors from USA to www.whitehouse.gov by inserting a meta tag
if(typeof(sGeobytesLocationCode)!="undefined" && sGeobytesLocationCode.indexOf('US')==0) {
    // document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=https:\\www.whitehouse.gov'>");
}
</script>
</head>
<body>
<a href="http://www.geobytes.com/geodirection/" target="_blank">GeoBytes API</a>
<p>    
<script type="text/javascript">
    document.write('sGeobytesLocationCode = ' + sGeobytesLocationCode );
</script>
</body>
</html>
&#13;
&#13;
&#13;