Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me with the difference between window.location.href and window.open() methods in JavaScript?

1 Answer

0 votes
by (26.7k points)

Basically, window.location.href is not a method, it is used to provide the current URL location of your browser. Also, by changing its property it can redirect the page. Whereas, window.open() is a method that is used to open the URL in a new window. For example:

window.location.href:

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

window.open():

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

I hope this will help.

Want to become a Java Expert? Join Java Training now!!

Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Tutorial:

Related questions

0 votes
1 answer
asked Feb 16, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Mar 31, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...