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
• 8,730 points
1,319 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
• 8,980 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
50 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
348 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,280 points
61 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,280 points
28 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,280 points
137 views
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
212 views
0 votes
1 answer

Migrating proxy npm repo in nexus 3

I don't think you can achieve this ...READ MORE

answered Jun 22, 2018 in DevOps Tools by DareDev
• 6,890 points
794 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
• 8,980 points
244 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
• 8,980 points
41 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP