页面重定向未加载

时间:2015-07-18 16:56:16

标签: javascript redirect

出于某种原因,我使用它时,此页面不会转到移动或桌面页面!这是代码:

<html>
    <head>
        <title>Loading...</title>
    </head>
    <script>
        window.onload = function() {
        var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
        if (iOS == true) {
        window.location.href="http://m.lifewithzooza.x10host.com/";
        } else {
        window.location.href="http://lifewithzooza.x10host.com/wordpress/";
        }
    </script>
    <body bgcolor="#FFFFFF">
        Loading...
    </body>
</html>

抱歉,这是我第一次使用Stack Overflow,所以我对某些内容并不熟悉。感谢。

3 个答案:

答案 0 :(得分:0)

您缺少} 。所以它不起作用。您错过了window.onload = function() { //your code goes here }

}

请检查此处的运行代码

 window.onload = function() {
        var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
        if (iOS == true) {
        window.location.href="http://m.lifewithzooza.x10host.com/";
        } else {
        window.location.href="http://lifewithzooza.x10host.com/wordpress/";
        }
   }
<html>
    <head>
        <title>Loading...</title>
    </head>
   
    <body bgcolor="#FFFFFF">
        Loading...
    </body>
</html>

答案 1 :(得分:0)

您错过了}功能的结束onload。将代码更新为以下内容。

window.onload = function() {
        var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
        if (iOS == true) {
        window.location.href="http://m.lifewithzooza.x10host.com/";
        } else {
        window.location.href="http://lifewithzooza.x10host.com/wordpress/";
        }
}

答案 2 :(得分:0)

2个问题:

  • 您已将script元素放在错误的位置,在不知名的地方。脚本标记必须位于bodyhead下,而不是其他内容。如W3The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of an HTML document.
  • 所述
  • 您的}功能错过onload
<html>
    <head>
        <title>Loading...</title>
        <script>
        window.onload = function() {
            var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
            if (iOS) {
                window.location.href="http://m.lifewithzooza.x10host.com/";
            } else {
                window.location.href="http://lifewithzooza.x10host.com/wordpress/";
            }
        }
    </script>
    </head>
    <body bgcolor="#FFFFFF">
        Loading...
    </body>
</html>
相关问题