-1

I am using below code for automatically redirect to the page in a fraction of seconds.

<script language="Javascript" type="text/javascript">
<!--
var testTimerID;

testTimerID = window.setTimeout(autoDirect, 30*250 );

function autoDirect() {
window.location = 'home';
}
</script>
  • This script works fine in all browser except in safari browser.it does not automatically redirect to the another page(home). what is the issue?.how can i solve it?.
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Ravichandran Jothi
  • 3,028
  • 11
  • 52
  • 82

2 Answers2

1

Try it like this:

<script language="Javascript" type="text/javascript">
//<!--
var testTimerID;

testTimerID = window.setTimeout(function(){
    window.location.href = '/home';
}, 30*250 );
//-->
</script>

Usually JS does not work properly and in same way through all the web browsers... Therefore I advise to use jQuery as it is debugged for all common browsers...

Try aslo reading through this: How to redirect to another webpage in JavaScript/jQuery?

Also instead of relative URL You shoudl use absolute like http://www.mydomain.com/home/, so the code should be:

...
    window.location.href = 'http://www.mydomain.com/home/';
...

.

Community
  • 1
  • 1
shadyyx
  • 15,825
  • 6
  • 60
  • 95
  • Why on earth would a simple redirect work better in jQuery than in simple javascript??? -1 for that but +1 for the absolute or complete url – mplungjan May 03 '11 at 11:33
  • I always recommend using of jQuery instead of plain JS just cos of different JS implementation through many web browsers... While with plain JS You have to check for browser and serve appropriate JS code with jQuery You just don't have to care... – shadyyx May 03 '11 at 11:38
  • hi i have another solution – Ravichandran Jothi May 03 '11 at 11:42
  • for a setTimeout and a window.location the code is identical on all browsers. In this case I am sure @Ravi is missing to give use some information. – mplungjan May 03 '11 at 12:26
0

This works perfectly in Safari 5 for windows

<script language="Javascript" type="text/javascript">
var testTimerID;

testTimerID = window.setTimeout(autoDirect, 30*250 );

function autoDirect() {
  window.location = 'http://google.com/';
}
</script>
mplungjan
  • 169,008
  • 28
  • 173
  • 236