I need to redirect the user using JavaScript. Which is the preferred method?
window.open("webpage.htm", "_self"); or
window.location.href = "webpage.htm"; Definitely the second method is preferred because you don't have the overhead of another function invocation:
window.location.href = "webpage.htm"; ../../folder/page.aspx?Source=abcd does not work. I needed to use the other method to make my link work and even then couldn't use "_self" with it.Hopefully someone else is saved by reading this.
We encountered an issue with webkit based browsers doing:
window.open("webpage.htm", "_self"); The browser would lockup and die if we had too many DOM nodes. When we switched our code to following the accepted answer of:
location.href = "webpage.html"; all was good. It took us awhile to figure out what was causing the issue, since it wasn't obvious what made our page periodically fail to load.
Please use this
window.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".
"_self"there...