Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
Date de publication: 2014/01/28
Shakeel Ishaq
par 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
par 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
par 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
par Samir Alkhatib , IT Support Engineer , Vianeos

one is a property and the other is method :)

Muhammad Majid Saleem
par 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