I need to redirect the user using JavaScript. Which is the preferred method?
window.open("webpage.htm", "_self");
or
window.location.href = "webpage.htm";
open("url","_self"); The first parameter "url" is full path of which page you want to open. The second parameter "_self", It's used for open page in same tab. You want open the page in another tab please use "_blank".
The URL of the page to open. If no URL is specified, a new blank window/tab is opened. name. Optional. The target attribute or the name of the window.
The Location href property in HTML is used to set or return the complete URL of the current page. The Location href property can also be used to set the href value point to another website or point to an email address.
Definitely the second method is preferred because you don't have the overhead of another function invocation:
window.location.href = "webpage.htm";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With