Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window.location.href () and Window.open () in JavaScript

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

like image 776
khalid jarrah Avatar asked Sep 05 '13 10:09

khalid jarrah


2 Answers

window.location is an Object and

window.location.href is its property

It tells you the current URL location of the browser

document.write(location.href);// will give location URL location of browser.

Setting the property 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

E.g

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

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

like image 182
Deepak Ingole Avatar answered Oct 03 '22 15:10

Deepak Ingole


window.location.href changes the immediate window location.

window.open() will open a new window.

like image 45
Lloyd Avatar answered Oct 03 '22 14:10

Lloyd