document.URL 和 location.href 之间的区别
我知道 document.URL
无法设置,而 location.href
可以。
但文件指出:
URL 是 DOM Level 0
location.href
属性的替代品。
那么我们什么时候会使用document.URL
呢?
I know that document.URL
can not be set, while location.href
can.
But the Document indicates:
URL is a replacement for the DOM Level 0
location.href
property.
So when would we use document.URL
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获取 document.URL,但无法设置它。
您可以获取和设置
location.href
。在某些网络浏览器中,您可以设置
document.URL
但请不要这样做,因为它在大多数浏览器中不起作用。你自己已经给出答案了!
在此处了解更多信息
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!
Learn more here
就获取数据而言,它们是可以互换的,但正如您所指出的,无法设置 document.URL 。我总是使用
location.href
因为它是一个 getter/setter。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!