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

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

+7
javascript windows
source share
2 answers

window.location - Object and

window.location.href is a property

It tells you the current location of the browser URL

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

When setting the property will redirect the page.

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

eg

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.

+20
source share

window.location.href changes the location of the immediate window.

window.open() will open a new window.

+5
source share

All Articles