JavaScript redirection issue on Google Chrome
10,629
Solution 1
try
<script type="text/javascript">
<!--
document.location="http://www.example.com/";
-->
</script>
Solution 2
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.com/"); } --> </script>
Solution 3
Have you tried using,
window.location.href = "http://www.example.com/";
As per the docs, https://developer.mozilla.org/en/DOM/window.location#Properties
Author by
I-M-JM
Updated on June 04, 2022Comments
-
I-M-JM almost 2 years
I have the following code on an html page:
<script type="text/javascript"> <!-- window.location.replace("http://www.example.com/"); --> </script>
and
<meta http-equiv="refresh" content="0;url=http://www.example.com/" >
On Google Chrome, it loads this page and then redirects to example.com, 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.com
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