May 29, 2013
kalpesh

jQuery redirect page, with javascript alternative

jQuery javascript frameworkjQuery redirect one page to another using the following code:

1
2
var your_url = 'http://ka.lpe.sh/'; //change this to your url
$(location).attr('href','your_url');

Above code works to redirect page in jQuery, but javascript code is good alternative here.

Using javascript to redirect your page using below code, which is better than jQuery, will do the job:

1
window.location.replace("http://ka.lpe.sh/");

Another javascript approach which will mock as if the URL is being clicked to redirect is:

1
window.location.href = "http://ka.lpe.sh/";

Even this will do the trick in javascript, which sets your URL in a window object and assigns it to anchor tag’s href attribute automatically:

1
window.location = "http://ka.lpe.sh/";

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications