Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.open target _self v window.location.href?

Tags:

javascript

I need to redirect the user using JavaScript. Which is the preferred method?

window.open("webpage.htm", "_self"); 

or

window.location.href = "webpage.htm"; 
like image 512
Rebecca Avatar asked Jan 27 '11 07:01

Rebecca


People also ask

What is _self in window open?

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".

What is window open target?

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.

What does setting window location href do?

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.


1 Answers

Definitely the second method is preferred because you don't have the overhead of another function invocation:

window.location.href = "webpage.htm"; 
like image 59
Jacob Relkin Avatar answered Sep 28 '22 18:09

Jacob Relkin