I am trying to redirect the user to a different page after 1 second via javascript:
setTimout("document.location.href='new_page.html'", 1000);
however, in Internet Explorer, this happens immediately, not 1 second later. Any thoughts?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you’ve quoted should work, except for a couple of minor errors:
You’re missing the “e” in setTimeout
You’re using
document.location; it should bewindow.location.Just tested it on IE8 and it waited as expected. Are you doing this from within some event that would make the page reload anyway, like a form’s
submitevent? If so, you’ll need to cancel the form submission to avoid that superceding yoursetTimeoutcode. How you do that will depend on how you’re hooking the event (e.g., if you’re using a DOM0onsubmit="..."handler, usereturn false;; if you’re using something more modern, you wantevent.preventDefault(); if you’re using jQuery, Prototype, or some other library, check their docs for the right way to prevent the default action of the event).Now, although it works the way you did it, it’s typically better to do this with a function rather than code within a string, e.g.:
But either way should work.