我知道document.URL
不能设置,而location.href
可以。
但是文档指出:
URL is a replacement for the DOM Level 0
location.href
property.
那我们什么时候使用document.URL
呢?
最佳答案
您可以获取 document.URL,但您不能设置它。
您可以获取和设置 location.href
。
在某些网络浏览器中,您可以设置 document.URL
但请不要这样做,因为它在大多数浏览器中不起作用。
你自己给出了答案!
var currentURL = document.URL;
alert(currentURL);
关于javascript - document.URL 和 location.href 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5388036/