Communiquez avec les autres et partagez vos connaissances professionnelles

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

Suivre

What is the difference between window.location.href () and window.open () methods in JavaScript?

user-image
Question ajoutée par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
Date de publication: 2013/07/08
Fadi Alkhateeb
par Fadi Alkhateeb , Senior Front End Developer , NexTwo

window.location.href is a property from (window.location), it returns current url location in browser and when change it it will redirect the same page to the new url.
window.location.href = 'yourwebsiteurl'; window.open() is a method that will open the page you request inside it in new window.
window.open('yourwebsiteurl');

irfan shaikh
par irfan shaikh , Consultant : Senior Web Designer/Front end Developer , Client : ● Impact Proximity, Dubai ● Cube Solution, Dubai ● WAC, Sharjha ● KIOEC, Kuwait ● IRIS Ltd.

window.location.href is JS property used for when you want to redirect to another page or url for Ex.
window.location.href = 'http://www.yahoo.com' will redirect to yahoo.com window.open() : open a new window with specific location or url for ex.
window.open("http://yahoo.com"); will open yahoo.com in new popup window you can define various parameter to window.open() like : height, width, scrollbar=yes/no, statusbar etc.

Osama Gamal
par Osama Gamal , Software Consultant , Ministry of Interior

window.location.href gets current URL of your browser.
window.open() is a method used to open new page by specifying page url using it.

samir diab
par samir diab , Je Poseur Maison , informatique

window.location.href is a property from (window.location), it returns current url location in browser and when change it it will redirect the same page to the new url.
window.location.href = 'yourwebsiteurl'; window.open() is a method that will open the page you request inside it in new window.
window.open('yourwebsiteurl

Rahif Abboud
par Rahif Abboud , Information Management / Database & Web Specialist , United Nations

window.location.href is used to redirect the page to another while window.open() is use for opening the link in a new window.
window.location.href could also be used to know the current address of the page if no value is passed to it.

rajveer singh jhala
par rajveer singh jhala , Software Programmer , Dotsquares technology pvt ltd

1 Window.location.href() will redirect the page to provided URL2 Window.OPen Is used to open the popup window

Muhammad Umer Jaffer
par Muhammad Umer Jaffer , Lead Software Engineer , Emaratech

Window.location.href is a property which provides the URL of the current. If it is set to a different URL than the one which you are currently on then the browser window redirects to that page. Window.open is a method which gives you the option to open a page in new window. By setting parameters you can make it open in the same window.

Osama Abu Rayyan
par Osama Abu Rayyan , Web Developer / Front-End Web Developer , BloomThemez

window.location.href : is not a method, it's a property to get current page url.
window.open('url') : is a method to open the url in new browser windows.

Abd-elhameed Quraim
par Abd-elhameed Quraim , Software Development Team Leader , Seventh Dimension eGlobal

window.location.href is used for redirection window.open(); it opens a popup window

Munsif Mulla
par Munsif Mulla , Senior UI Engineer , FreeCharge

Both have same functionality.
as both opens you a page with specified URL but the actions are different1.
window.open() -> this open you an Page for Specified URL in a new Browser Window2.
window.location.href -> this open you an Page for Specified URL in the same Browser Window

Pradeep Chand
par Pradeep Chand , Web Developer , Alitum Solutions

window.location.href() is used to know the current window address or to change the current window address.
window.open is used to open a link address in new tab or new window.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?