javascript document.location.href 在 Chrome 浏览器中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13209214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:04:49  来源:igfitidea点击:

The document.location.href is not working in Chrome browser

javascriptgoogle-chromeinternet-explorer-9locationhref

提问by Ashwin G

The command:

命令:

document.location.href="www.google.com" 

Does not change the current web page in the google chrome browser. The command does transfer the page in the IE9 browser.

不会更改 google chrome 浏览器中的当前网页。该命令确实在 IE9 浏览器中传输页面。

Why would this command work for IE9 but not for chrome?

为什么这个命令适用于 IE9 而不适用于 chrome?

回答by Mendhak

You need to add the protocol:

您需要添加协议:

document.location.href="http://www.google.com";

回答by Ashwin G

An alternative solution is to add this line before document.location.href

另一种解决方案是在此之前添加此行 document.location.href

window.event.returnValue = false;

Source: document.location does not change the webpage in IE9?

来源:document.location 不改变IE9中的网页?