Jquery window.location.href不适用于Chrome

Jquery window.location.href不适用于Chrome,jquery,google-chrome,window.location,Jquery,Google Chrome,Window.location,此代码适用于Firefox,但不适用于Chrome。我相信这是window.location.href,但我能做些什么来让chrome完成这项工作呢。基本上,这会切换页面 <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.6.4.js"></script> <script> $(document).keydown(f

此代码适用于Firefox,但不适用于Chrome。我相信这是window.location.href,但我能做些什么来让chrome完成这项工作呢。基本上,这会切换页面

<!DOCTYPE html>
<html>
 <head>
    <script src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script>
$(document).keydown(function(e){    
    if (e.keyCode == 37) {  // left
       window.location.href = $('#prev').attr('href');   
       return false;
    } else if (e.keyCode == 39) {  // right
       window.location.href =  $('#next').attr('href');  
       return false;
    }
});


</script>


   </head>
 <body>


  <div style="display:hidden;">
    <a id="next" href=<?php echo "readerapp.php?mode=$mode&pagenumber=$next";?>></a>
    <a id="prev" href=<?php echo "readerapp.php?mode=$mode&pagenumber=$last";?>></a>
</div>
   </body>
</html>

$(文档).keydown(函数(e){
如果(e.keyCode==37){//left
window.location.href=$('#prev').attr('href');
返回false;
}如果(e.keyCode==39){//right
window.location.href=$('#next').attr('href');
返回false;
}
});

发送到浏览器的路径是相对的。您需要向JS提供完整的URL。试试这个:

window.location.href = 'http://'+ window.location.host + $('#next').attr('href');
举个简单的例子:

在此页面上,用chrome(Shift+CTRL+j)打开控制台并键入:

window.location.href = 'http://' + window.location.host + $('.bottom-notice a:last').attr('href');

它会将您重定向到

使用
窗口尝试。位置

$(document).keydown(function(e){
    if (e.keyCode == 37) {  // left
        window.location = $('#prev').attr('href');   
        return false;
    } else if (e.keyCode == 39) {  // right
        window.location =  $('#next').attr('href');  
        return false;
    }
});

重新启动Chrome后,我的问题消失了。

我也遇到了同样的问题,我找到了两个解决方法。第一种方法是设置超时帧,因此代码如下:

setTimeout(function () { document.location.href = "nextpage.html" }, 1000);
第二种解决方案是将下一页分配给window.location,如下所示:

window.location.assign("nextpage.html");

希望有帮助。

单击
输入类型=“提交”
不允许脚本设置
位置。href


一个
input type=“button”
很好用。

所以我知道这有点老掉牙,但因为它是谷歌搜索时的#1结果,所以我想在这里加上我的2美分

对我来说,问题在于我在fancyBox中执行此操作,然后立即调用“parent.jQuery.fancyBox.getInstance().close();”。在IE中,这很好,但我猜在Chrome中,通过调用.close(),它阻止了重定向的工作


解决办法就是把那条线去掉。window.location.href强制其关闭,因为主窗口已重定向。

PHP返回什么值?它在chrome中工作。你使用的是哪个版本的chrome?我收到了这个问题,并在window.location.host中添加了meDifference?你为什么认为这应该有效?那
href
呢?这是我在所有浏览器(甚至是手机)上都能使用的唯一解决方案。
document.location.href=“nextpage.html”
不起作用,但当我添加timout时,它就起作用了。