Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.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 在android浏览器中重定向到document.ready上的其他页面_Javascript_Android_Html_Redirect_User Interface - Fatal编程技术网

Javascript 在android浏览器中重定向到document.ready上的其他页面

Javascript 在android浏览器中重定向到document.ready上的其他页面,javascript,android,html,redirect,user-interface,Javascript,Android,Html,Redirect,User Interface,我试图在加载一个页面时重定向到另一个html页面。下面是我的代码(我想在打开1.html时自动加载2.html) P.S:由于特定的用例,我无法使用window.location.href 1.html <html> <head> <script src="jquery-2.1.1.min.js"></script> <script type = "text/javascript"> $( document )

我试图在加载一个页面时重定向到另一个html页面。下面是我的代码(我想在打开1.html时自动加载2.html) P.S:由于特定的用例,我无法使用window.location.href

1.html

<html>
<head>
    <script src="jquery-2.1.1.min.js"></script>
    <script type = "text/javascript">

    $( document ).ready(function() {
        //$("#second")[0].click();
        document.getElementById("second").click(); 
    });
    </script>
</head>
<body>
    <a href = "2.html" id="second"/> click </a>
</body>
</html>

$(文档).ready(函数(){
//$(“#秒”)[0]。单击();
document.getElementById(“第二个”)。单击();
});
我尝试了$(“#秒”)[0]。单击()文档。getElementById(“秒”)。单击()。两者在桌面浏览器中都可以正常工作。但在安卓系统中,两者似乎都不起作用。 我们有什么办法来实现它吗?请帮助使用此代码

解决方案1

函数newPage(){
window.location.assign(“http://www.adarshkr.com")
}
解决方案2

变量url=”http://stackoverflow.com";    
$(location.attr('href',url);

感谢@mod和@samsad。我用下面的方法解决了这个问题

 <html>
        <head>
            <script src="jquery-2.1.1.min.js"></script>
            <script type = "text/javascript">

            window.onunload = function(){};
            $( document ).ready(function() {
                history.pushState({}, "", "1.html");
                var url = "2.html";    
                window.location.assign(url);
            });
            </script>
        </head>
        <body>
            <a href = "2.html" id="second"/> click </a>
        </body>
        </html>

window.onunload=函数(){};
$(文档).ready(函数(){
pushState({},“,“1.html”);
var url=“2.html”;
window.location.assign(url);
});

要重定向手机中的页面,请检查此问题您好,我无法使用window.location.href/replace,因为我需要在浏览器历史记录中显示此1.html。请检查我发送的问题中的解决方案,将
replaceState
替换为
pushState
应该可以帮您解决问题。它似乎在安卓系统中工作,但它过去不工作,有些版本可以使用,有些则不行。在这种情况下,也许你可以在不修改历史记录的情况下使用回退。这个脚本在android中执行重定向。但问题是它没有为我的1.html添加历史记录条目
<script>    
    var url = "http://stackoverflow.com";    
    $(location).attr('href',url);

</script>
 <html>
        <head>
            <script src="jquery-2.1.1.min.js"></script>
            <script type = "text/javascript">

            window.onunload = function(){};
            $( document ).ready(function() {
                history.pushState({}, "", "1.html");
                var url = "2.html";    
                window.location.assign(url);
            });
            </script>
        </head>
        <body>
            <a href = "2.html" id="second"/> click </a>
        </body>
        </html>