Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between document.URL and location.href

People also ask

What is document location href?

The location. href property sets or returns the entire URL of the current page.

What is difference between document location and window location?

window. location is read/write on all compliant browsers. document. location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).


You can get the document.URL, but you can not set it. You can both get and set the location.href.

In some webbrowsers, you are able to set the document.URL but please don't, as it doesn't work in most browsers.

You gave the answer yourself!

var currentURL = document.URL;
alert(currentURL);

Learn more here


They're interchangeable as far as getting data is concerned, but as you pointed out document.URL can not be set. I just always use location.href since it's a getter/setter.