Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the diffrence between Window.location.href () and Window.open () ?

user-image
Question added by Zaid Rabab'a , Technical Team Lead , ESKADENIA Software
Date Posted: 2014/01/28
Shakeel Ishaq
by Shakeel Ishaq , Senior Project Manager

window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different will redirect the page.

Example:

window.location.href = 'http://www.google.com'; //Will take you to Google.

 

window.open() is a method that you can pass a URL to that you want to open in a new window. 

Example:

window.open('http://www.google.com'); //This will open Google in a new window.

Mahmoud Elmahdi
by Mahmoud Elmahdi , UX/UI Designer, Web Developer , ikantam.com

window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different will redirect the page.

 

window.open() is a method that you can pass a URL to that you want to open in a new window. For example:

 

window.location.href example:

window.location.href = 'http://www.google.com';  //Will take you to Google.

 

window.open() example:

window.open('http://www.google.com');  //This will open Google in a new window.

Arun Raj Alampatta
by Arun Raj Alampatta , Senior Software Engg. , Orion India Systems

Window.location.href using to redirect specified page in same window.

Window.Open it open a new window or new tab and we can manage nature, height, width,etc.

Samir Alkhatib
by Samir Alkhatib , IT Support Engineer , Vianeos

one is a property and the other is method :)

Muhammad Majid Saleem
by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

Key differences between window.location and window.open are:

Window.Open

- It is a method.

- It accepts few parameters like window.open(URL,name,specs,replace).

- It accepts a URL and opens it to a new window.

- For example http://www.w3schools.com/jsref/met_win_open.asp

 

Window.location.href

- It is not a method but a string representation.

- It returns the location of the current page.

More Questions Like This