Redirect to another page on load

You can redirect a web page via JavaScript using a number of methods. If you want a cross-browser compliant JavaScript redirect script, better to use the following scripts.
window.location.href = url;
window.location.href = "";

You can use window.location object to load another page in JavaScript.

window.location = "";

Difference between window.location and location.href

  1. window.location is an object that holds all the information about the current document location (host, href, port, protocol etc.).

  2. location.href is shorthand for window.location.href (you call location from global object - window, so this is window.location.href), and this is only a string with the full URL of the current website.

Other methods of JavaScript redirection

Assigns a new URL to the current window.


Replaces the location of the current window with the new one.


Sets the location of the current window itself.

self.location = "";

Sets the location of the topmost window of the current window.

top.location = "";