Articles

jQuery Redirect Page After 5 Seconds Example

Redirecting Page using jQuery will help you to redirect to a page and this can be done with  help of just 1 line of code. Examples to page redirection using jQuery are provided. Read on to find out more on how to do this.

How to Redirect Page using jQuery – Examples

Example 1: Redirect Page to another website without any delay using jQuery

var url = "http://www.theextremewebdesigns.com";
$(location).attr('href',url);

Example 2: Redirect Page to a specific page of a website using jQuery

If you would rather redirect to a specific page of a website, use the following code:

var url = "http://www.theextremewebdesigns.com/services.php";
$(location).attr('href',url);

Example 3: Redirect Page after 5 seconds using jQuery

If you would like to redirect to a website after a delay of 5 seconds, use the following code:

var url = "http://www.theextremewebdesigns.com";

//5000 is the number of milliseconds (or 5 seconds) that you want to wait before redirection.
var delay = 5000;
setTimeout(function() {
window.location.href = url;
}, delay);

Example 4: Redirect Page on button click using jQuery

If you would like to redirect to a website after a delay of 5 seconds when a button is clicked, use the following code:

$("#my_button").click(function()
{
var url = "http://www.theextremewebdesigns.com";
//5000 is the number of milliseconds (or 5 seconds) that you want to wait before redirection.
var delay = 5000;
setTimeout(function() {
window.location.href = url;
}, delay);
});
That’s it!

Do you know of any other ways to redirect page using jQuery? Please feel free to share by commenting below.

Share your thoughts, comment below now!

*

*