window location href and window open methods in JavaScript

0 votes

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

Feb 9 in Java by Soham
• 9,670 points
4,188 views

1 answer to this question.

0 votes

To answer your question, first of all, the window.location.href is not a method but rather is a property that will tell you the current location of the URL of the browser. Following which, by changing the value of the property which will redirect the page.

The 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.

Please note that window.open() can be passed through additional parameters.

answered Feb 9 by Rahul
• 9,680 points

Related Questions In Java

0 votes
0 answers

window.location.href and window.open () methods in JavaScript

What is the difference between window.location.href and ...READ MORE

Apr 26 in Java by Rahul
• 3,380 points
106 views
0 votes
1 answer

What is the need to override the equals and hashCode methods in Java?

You must override hashCode() in every class ...READ MORE

answered Jan 2, 2019 in Java by Daisy
• 8,120 points
459 views
0 votes
1 answer

How to merge two arrays in JavaScript and de-duplicate items?

With Underscore.js or Lo-Dash you can use: console.log(_.union([1, ...READ MORE

answered Feb 18 in Java by Aditya
• 7,660 points
117 views
0 votes
0 answers

window.location.href and window.open () methods in JavaScript

What is the difference between window.location.href and ...READ MORE

Sep 20 in Java by Nicholas
• 7,120 points
62 views
0 votes
1 answer

Cannot open local file - Chrome: Not allowed to load local resource

To answer your query, start with opening ...READ MORE

answered Feb 18 in Java by Aditya
• 7,660 points
2,490 views
0 votes
1 answer

Open a URL in a new tab (and not a new window)

Nothing an author can do can choose ...READ MORE

answered Feb 23 in Java-Script by Aditya
• 7,660 points
1,203 views
0 votes
0 answers

Javascript - Window open, use CDN

Simple question. I cannot get a new ...READ MORE

Jul 20 in Web Development by gaurav
• 22,040 points
34 views
0 votes
1 answer

JSON formatter in C#?

 In order to do the needful, one ...READ MORE

answered Feb 8 in Java by Rahul
• 9,680 points
959 views
0 votes
1 answer

What does "javascript:void(0)" mean?

The href of the link helps with ...READ MORE

answered Feb 8 in Java by Rahul
• 9,680 points
118 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP