Javascript:location.hostname 和 document.domain 之间的区别?

标签 javascript dns hostname

使用 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.domainwindow.location.hostname 更新为新值,然后查看差异。

关于Javascript:location.hostname 和 document.domain 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4226111/

相关文章:

bash - 如何确定哪些主机名未解析为 IP 地址?

C# Dns.GetHostEntry 不返回连接到 WiFi 的移动设备的名称

javascript - 单击元素后禁用 .toggleClass

windows - DNS 问题,nslookup 有效,ping 无效

azure - 将 Azure 流量管理器与应用服务 (HTTPS) 结合使用

java - 当我的机器进行 DNS 查询时,如何动态设置源 IP 地址?

asp.net - 不使用HttpRequest获取主机名

javascript - 标准主体中是否有任何动议来支持安全地复制到剪贴板的方法?

javascript - 正则表达式相当于 str.substr(0, str.indexOf ('foo' ))

javascript - node.js 使用 mongoose 链接多个异步函数