Google Chrome上的JavaScript重定向问题

Google Chrome上的JavaScript重定向问题,javascript,google-chrome,redirect,Javascript,Google Chrome,Redirect,我在html页面上有以下代码: <script type="text/javascript"> <!-- window.location.replace("http://www.example.com/"); --> </script> 及 在Google Chrome上,它加载此页面,然后重定向到example.com,而在我测试过的其他浏览器(IE和Firefox)上,它不加载此HTML页面(此特定代码在其上),而是直接显示example

我在html页面上有以下代码:

<script type="text/javascript">
<!--
    window.location.replace("http://www.example.com/");
-->
</script>


在Google Chrome上,它加载此页面,然后重定向到example.com,而在我测试过的其他浏览器(IE和Firefox)上,它不加载此HTML页面(此特定代码在其上),而是直接显示example.com

有人能告诉我我的代码有什么问题吗?有什么改进的建议吗?,这样它也能在Google Chrome上运行

谢谢

试试看

<script type="text/javascript">
<!--
    document.location="http://www.example.com/";
-->
</script>

试试这两种方法

<script type="text/javascript">
    document.location="http://www.example.com/";
</script>

<script type="text/javascript">
    document.location.href="http://www.example.com/";
</script>

文档位置=”http://www.example.com/";
document.location.href=”http://www.example.com/";

如果您这样编写代码,它可能会按照您的意愿工作:

<script type="text/javascript"> <!-- window.onload = function(){ window.location.replace("http://www.example.com/"); } --> </script> 你试过使用

window.location.href = "http://www.example.com/";

根据文档,

在我的例子中,我重定向到同一个页面,但在url的末尾设置了一个不同的目标。没有任何工作,包括随后返回false,但修复的是在设置URL后重新加载页面,如下所示(在本例中,仅在延迟6秒后触发):


问题是它没有被重定向或者什么?看,我们怎么知道问题到底是什么但我觉得Chrome比其他浏览器更能正确地实现这一点。仍然会加载包含此代码的页面。在我看来,使用.replace()方法进行页面转发是一种肮脏的方式。
window.location.href = "http://www.example.com/";
setTimeout(function () {            
    window.location.href = redirectUrl;
    window.location.reload(true);
    return false; // maybe not needed...
}, 6000);