How to Redirect to another Page using jQuery – Undertand jQuery Redirection.

In this post i will show you a various methods and examples to redirect user to another page or URL by using jQuery. It is better to use window.location.replace() instead of window.location.href() because the function do not store the redirected page in the browser history and session. window.location.href() function works on every browser.

For Example.

//Behave like Http redirect.
window.location.replace(“http://whyblogging.com”);

// behave like as click on links.
window.location.href = “http://whyblogging.com”;

$(location).attr(‘href’, http://whyblogging.com);

If you can do without jQuery use window.location = “example.com”; and would like to do by using only jQuery$jq(window).attr(“location”,”example”);

Here is another cool example of jQuery redirect.

function YourJavaScriptFunction()
{
var i = $(‘#login’).val();
if (i == ‘login’)
window.location = “login.php”;
else
window.location = “Logout.php”;
}

This the code above you can redirect the user to the login page if he is not login else redirect to the logout page. A JavaScript function window.location is used to perform the task. Redirect the user to external page add full path like window.location = “http://whyblogging.com”;, hope now you can understand how to redirect user to another page in jQuery.

About Moazzam Qureshi

I am SEO expert and web developer since 2011. My hobby is to write & provides quality content about blogging, SEO , Social Media , Earn Online and Affiliate Marketing.