Redirect using JavaScript/jQuery

Redirect using JavaScript/jQuery with href and replace. There are multiple ways to redirect users to one page from another page. Among all these methods, some need user interactions and some do auto redirects. Some of the multiple ways are: replace, href, assign, etc.
The most commonly used and efficient ways are replace and href. Because they are mostly supported by every browser. Let’s check them in detail.

If you want to simulate someone clicking on the link, use location.href

If you want to simulate an HTTP redirect, use location.replace


window.location.href = "";

Some other ways are:

// window.location
window.location.href = ''
document.location.href = '/path'

// window.history

// window.navigate; ONLY for old versions of Internet Explorer

// jQuery
$(location).prop('href', '')

You can get more details about this topic here.
To get to know more about other JavaScript topics, you can check these articles too.

Please follow and like us:

Related Posts

Leave a Reply