JavaScript redirect

Redirect is nothing but a mechanism of sending search engines and users on a different URL from the original one. The redirected page can be on the same server or on a different server. It can also be on the same website or on different websites. Sometimes when we clicked on a URL, we directed to another URL. It happens because of the page redirection. It is different from refreshing a page.

There are a couple of ways to redirect to another webpage with JavaScript. The most popular ones are location.href and location.replace:


// Simulate a mouse click:
window.location.href = "";

// Simulate an HTTP redirect:

Example -