window.location.replace()无法重定向浏览器 [英] window.location.replace() not working to redirect browser

查看:1215
本文介绍了window.location.replace()无法重定向浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用网页进行导航,但此代码不起作用,有什么问题?

I make navigation with pages but this code not work, what's the problem ?

<script>
$(document).ready(function() {
$("body").keydown(function(event) {
  if(event.keyCode == 37) { // left
    window.location.replace("http://newsii.abudayah.com/photo/2)";  }
  else if(event.keyCode == 39) { // right
    window.location.replace("http://newsii.abudayah.com/photo/31)";  }
});
});
</script>


推荐答案

请勿使用。替换()为此,只需直接赋值。

Don't use .replace() for this, just assign the value directly.

示例

$("body").keydown(function(event) {

    if(event.keyCode == 37) { // left
        window.location = "http://newsii.abudayah.com/photo/2";
    }
    else if(event.keyCode == 39) { // right
        window.location = "http://newsii.abudayah.com/photo/31"; 
    }

});

这篇关于window.location.replace()无法重定向浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆