tags:

views:

109

answers:

6
function redir(){
setTimeout(window.location = '/SV/main/main.html', 10);
}

I dont know if the delay is in miliseconds or seconds, but I have tried BOTH. (by adding three zeros).

Problem is, the redirect is made right away, without any delay at all... why?

Thanks

BTW its called like this: <body onload="redir();">

A: 

You're missing the href. Try

 window.location.href = '...'
Pekka
nope, same thing happens with .href !!! redirects right away...
Camran
Yes, I misread your question.
Pekka
+2  A: 

Try

setTimeout(function(){window.location = '/SV/main/main.html';}, 10);

10 is milliseconds.

S.Mark
+6  A: 

You have to put your javascript statement between quotes :

function redir(){
    setTimeout("window.location = '/SV/main/main.html';", 10);
}

The delay is in milliseconds btw.

As said in the comments and other answers, it is much cleaner to use an anonymous function to do such things :

function redir() {
  setTimeout(function(){
    window.location = "/SV/main/main.html";
  }, 10); // 10 milliseconds
}
Wookai
You can think of setTimeout as doing an eval() of the code you give it.
Wookai
Avoid using eval() wherever possible. You can pass a function as the first argument.
Michiel Kalkman
I agree ;) ! Using an anonymous function is definitely the way to go.
Wookai
eval = EVIL >:(
Matt Ball
+1  A: 

setTimeout takes a function and a timeout interval.

function redir() {
    setTimeout(function() {
        window.location = '/SV/main/main.html';
    }, 10);
}
Michiel Kalkman
A: 

You should use the href property of location, and wrap the code within a function.

window.setTimeout( function() { window.location.href = '/SV/main/main.html';} , 10 );
Tim Down
+3  A: 

Much cleaner way to write this:

function redir() {
  setTimeout(function(){
    window.location = "/SV/main/main.html";
  }, 10000); // fire after 10 seconds
}
Jonathan Sampson