[Javascript] Redirect the browser using JavaScript

Three methods to preform redirection in browser:

  1. widnow.location.href
  2. window.location.assign
  3. window.location.replace

1 & 2, they are pretty much the same, just 1 is the property and 2 is the function, some people say use property is a little bit faster than calling a function. So they prefer using 1th.

http://stackoverflow.com/questions/10302905/location-href-property-vs-location-assign-method

1: window.location.href="http://www.egghead.io";
2: window.location.assign("http://www.egghead.io");

 

The differeces between 1 & 2 with 3 is:

 replace(), is that replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.

你可能感兴趣的:([Javascript] Redirect the browser using JavaScript)