admin管理员组文章数量:1312916
I have the following code on an html page:
<script type="text/javascript">
<!--
window.location.replace("/");
-->
</script>
and
<meta http-equiv="refresh" content="0;url=/" >
On Google Chrome, it loads this page and then redirects to example, while, on other browsers that I have tested (IE and Firefox), it does not load this HTML page (on which this particular code is) but directly shows up example
Can any one tell me what's wrong with my code and any suggestions to improve it, so that it will also work on Google Chrome too.
Thanks
I have the following code on an html page:
<script type="text/javascript">
<!--
window.location.replace("http://www.example./");
-->
</script>
and
<meta http-equiv="refresh" content="0;url=http://www.example./" >
On Google Chrome, it loads this page and then redirects to example., while, on other browsers that I have tested (IE and Firefox), it does not load this HTML page (on which this particular code is) but directly shows up example.
Can any one tell me what's wrong with my code and any suggestions to improve it, so that it will also work on Google Chrome too.
Thanks
Share Improve this question edited Jan 15, 2011 at 13:12 I-M-JM asked Jan 15, 2011 at 13:03 I-M-JMI-M-JM 16k26 gold badges79 silver badges105 bronze badges 3- And the issue is that it is not redirected or what? – Felix Kling Commented Jan 15, 2011 at 13:06
- See, how could we have known what the issue really is? ;) But I have the feeling that Chrome implements this more correctly then the other browsers. The page containing this code is loaded anyway. Maybe the other browsers just don't render it. – Felix Kling Commented Jan 15, 2011 at 13:14
- in my eyes, using the .replace() method for page forwarding is a dirty way. – Reporter Commented Apr 27, 2011 at 10:21
5 Answers
Reset to default 2try
<script type="text/javascript">
<!--
document.location="http://www.example./";
-->
</script>
Maybe it will work as you want if you write your code like this:
<script type="text/javascript"> <!-- window.onload = function(){ window.location.replace("http://www.example./"); } --> </script>
Have you tried using,
window.location.href = "http://www.example./";
As per the docs, https://developer.mozilla/en/DOM/window.location#Properties
Try those two methods
<script type="text/javascript">
document.location="http://www.example./";
</script>
<script type="text/javascript">
document.location.href="http://www.example./";
</script>
In my case I was redirecting to the same page, but setting a different #target at the end of the url. Nothing was working, including returning false afterwards, but what fixed it was reloading the page after setting the URL, as follows (in this example, is only fired after a 6 second delay):
setTimeout(function () {
window.location.href = redirectUrl;
window.location.reload(true);
return false; // maybe not needed...
}, 6000);
本文标签: JavaScript redirection issue on Google ChromeStack Overflow
版权声明:本文标题:JavaScript redirection issue on Google Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741895110a2403530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论