JavaScript – Redirect to another web page

The below code shows you how to redirect users to another web page using JavaScript/jQuery.

1. If you want to simulate someone clicking on a link, use this:

  • pure JavaScript
window.location.href = '';
  • jQuery
$(location).attr('href', '')


2. If you want to simulate an HTTP redirect, use this:

  • pure JavaScript