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;
example
window.location.href = "https://net-informations.com";

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

example
window.location = "https://net-informations.com";

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.

window.location.assign("https://net-informations.com");

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

window.location.replace("https://net-informations.com");

Sets the location of the current window itself.

self.location = "https://net-informations.com";

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

top.location = "https://net-informations.com";