Difference between document.URL and location.href

最后都变了- 提交于 2019-11-28 18:32:59
rsplak

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.

Yes and no!

alert(document.url);  
document.url="http://www.google.co.uk";  
alert(document.url);  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!