[HTML] document domain 的说明

先来看段代码:

 

这段代码到底是什么意思呢?

 

首先,我们来看下HTML DOM 关于这个的说明:

domain of type DOMString, readonly
The domain name of the server that served the document, or null if the server cannot be identified by a domain name.

 这段话的意思是这个值是DOMString 类型的并且是只读的,如果找不到域名的话这个值为null,否则,这个值就是这个提供这个文档的域名。

 

再来看下firefox 关于这个值的说明

 

In the DOM HTML specification, this property is listed as being read-only. However, all common browsers including Mozilla will let you set it to a superdomain of the current value. For example, on developer.mozilla.org it is possible to set it to "mozilla.org" but not "mozilla.com".

It is not universally possible in all browsers to set document.domain to a top-level domain (such as "com" or "org") or to a subdomain of a domain on which registrations are restricted (e.g. "co.uk", as registrations on the "uk" domain are restricted).

    这段话的大致意思是虽然DOM 标准规定document.domain 这个值是只读的,但是许多浏览器包括火狐允许它设置为当前域名的父域名。比如‘developer.mozila.org’ 可以设置为‘mozila.org’的域名,但是不能设置为‘mozila.com’的域名。不同浏览器对这个值的设置支持不一致。

 

 

 根据我的实验,设置了这个domain值后,所有非写在标签事件中的JS都无法执行. 

 

document.domain是JavaScript中的一个属性,用于获取当前网页的域名。它可以帮助实现跨域操作。通过更改document.domain属性,可以使不同子域名之间的网页进行跨域通信。具体来说,当父域名相同而子域名不同的时候,通过设置document.domain为共同的父域名,就可以实现跨域操作。这样做的前提是需要在两个子域名下都设置相同的document.domain属性值。 然而,需要注意的是,通过更改document.domain属性进行跨域操作有一些限制和注意事项。首先,该方法只适用于主域名相<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [js设置document.domain实现跨域的注意点分析](https://download.csdn.net/download/weixin_38627104/13618996)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Chrome 又搞事情,这种跨域方案要被禁用了!](https://blog.csdn.net/weixin_39843414/article/details/122677775)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值