How to redirect page using Javascript or Jquery

Redirect Page using Javascript

There are multiple ways in JS to redirect page using javascript. The best way is to use window.location.href as it preserves the history when you hit the back button.Let us see multiple ways of implementing this in the below examples.

Example to redirect page using javascript using Javascript:

All the three code does the same job. It would redirect to the URL, however, the Location.replace() method replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History, meaning the user won’t be able to use the back button to navigate to it.

Redirect Page using Jquery

There are multiple ways of redirecting to a page in Jquery. Let us take a look of each one.

Example using Jquery:

If you are using Jquery to redirect to a page then you could use one of the above code for redirection.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.