View Full Version : how to delay window.location.href?

12-08-2009, 02:52 AM
I guess this is an easy question for all javascripters but I don't know how to manage (I'm pretty fresh with JS). I found two solutions on this forum but it seems that they don't work(?).

I want to delay for few seconds window.location.href="destination_site.html" before it will automatically take visitor to destination site. It has something to do with setTimeout but I would be greatful for posting a fixed code.

Thanks in advance.

12-08-2009, 02:54 AM
i this on click or on load?

Old Pedant
12-08-2009, 03:06 AM
Well, whether onclick or onload, the answer's really the same:


is working where it is, now, without the delay, then just use

setTimeout('window.location.href="destination_site.html"', 5000) /* 5 seconds */

Now, *if* that is indeed inline in something like

<body onload='window.location.href="destination_site.html"'>


<input type="button" onclick='window.location.href="destination_site.html"'>

Then it's trickier. Example:

<body onload='setTmeout("window.location.href=\"destination_site.html\"",5000)'>

12-08-2009, 03:51 PM
That works very good. Thanks.