出于某些原因,Chrome不再支持document.domain,并且当在包含子域的iframe中读取该行时,会在包含iframe的子域中抛出错误。是否有任何解决方法?
错误:未捕获的错误:SECURITY_ERR:DOM异常18
出于某些原因,Chrome不再支持document.domain,并且当在包含子域的iframe中读取该行时,会在包含iframe的子域中抛出错误。是否有任何解决方法?
错误:未捕获的错误:SECURITY_ERR:DOM异常18
文档域名应该使用小写字母,规则如下:
// Actual domain is "www.foo.com"
document.domain = "foo.com"; // this is valid
// Actual domain is "bar.foo.com"
document.domain = "www.foo.com"; // this is invalid, "bar.foo.com" is not a subdomain of "www.foo.com"
// Actual domain is "blah.bar.foo.com"
document.domain = "bar.foo.com" // Ok
document.domain = "foo.com" // Still ok
document.domain = "bar.foo.com" // Invalid, you can't change it back to a more specific domain.
document.domain
应该适用于 iframe,只要它们在同一个域名下:
iframe=document.querySelector('iframe');
console.log(iframe.contentDocument.domain)
如果您尝试访问一个与父框架不同域的iframe文档,您会看到安全错误。
请注意,子域被视为不同的域,因此您可能会遇到跨域问题:关于跨域(子域)ajax请求的问题