使用 location.hostname 和 document.domain 有什么区别?
我认为带示例的解释会有所帮助。
最佳答案
document.domain
似乎是一个只读 属性,但在 Mozilla 中除外,它允许您更改用于同源策略的域的值的(例如)AJAX 请求而不实际更新页面。
这方面的限制是同源策略的相同规则。
至少这是我对MDC docs for document.domain
的理解.
来自文档:
Gets/sets the domain portion of the origin of the current document, as used by the same origin policy.
...
In the DOM HTML specification, this property is listed as being read-only. However, Mozilla will let you set it to a superdomain of the current value, constrained by its base domain. For example, on developer.mozilla.org it is possible to set it to "mozilla.org" but not "mozilla.com" or "org".
尝试在控制台中将 document.domain
和 window.location.hostname
更新为新值,然后查看差异。
关于Javascript:location.hostname 和 document.domain 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4226111/