When would you set location
to a URL string versus setting location.href
?
location = "http://www.stackoverflow.com";
vs
location.href = "http://www.stackoverflow.com";
Mozilla Developer Network Reference
The Location href property in HTML is used to set or return the complete URL of the current page. The Location href property can also be used to set the href value point to another website or point to an email address.
The location. href property sets or returns the entire URL of the current page.
You might set location
directly because it's slightly shorter. If you're trying to be terse, you can usually omit the window.
too.
URL assignments to both location.href
and location
are defined to work in JavaScript 1.0, back in Netscape 2, and have been implemented in every browser since. So take your pick and use whichever you find clearest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With