JavaScript Redirect Methods
星期日, 十二月 17th, 2017In JavaScript, window.location or simply location object is used to get information about the location of the current web page (document) and also to modify it. The following is a list of possible ways that can be used as a JavaScript redirect:
// Sets the new location of the current window.
window.location = “https://www.example.com”;
// Sets the new href (URL) for the current window.
window.location.href = “https://www.example.com”;
// Assigns a new URL to the current window.
window.location.assign(“https://www.example.com”);
// Replaces the location of the current window with the new one.
window.location.replace(“https://www.example.com”);
// Sets the location of the current window itself.
self.location = “https://www.example.com”;
// Sets the location of the topmost window of the current window.
top.location = “https://www.example.com”;