Redirect page after 10 seconds
Have a page you want to show for a few seconds and then redirect? Most sites I create have a form submission confirmation message done this way.
UPDATE: AN UPDATE TO THIS POST HAS BEEN MADE
EDIT: Had a couple inquires on this code, most people couldn’t get this to work because jQuery wasn’t loaded. Pease make sure you have jQuery loaded on your page before using this code. Not sure how to load jQuery? Check out this post
Here is the code to do it:
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
setTimeout("location.href='http://www.mysite.com/'", 10000);
});
// ]]></script>
Set http://www.mysite.com/ to the page you want to redirect to.
Set 10000 to the amount of time you want to wait. 10000 is 10 seconds, 5000 is 5 seconds, etc…
You can put this code anywhere on the page (remember to use the html editor and not the visual editor if you’re not putting this in your template file), it will wait until the page loads and fire the function to count down 10 seconds.
hello, exactly what i want to do from within page, but it is not working….
any ideas?
Try adding window. to the front of location like this:
$(document).ready(function() {
setTimeout(“window.location.href=’http://www.mysite.com/’”, 10000);
});
If that doesn’t work, do you get any jQuery errors on the page?
Works like a charm!! TKS
this is really useful for me thanks
How can I add attributes to the href? I need it to look like the HTML . Also, can I limit this to only happen 1 time per session? Is that just using setInterval instead?