zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Javascript] Redirect the browser using JavaScript

JavaScript The Using Browser Redirect
2023-09-14 08:59:20 时间

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.