文档域错误
document.domain bug
Permission denied for <http://www.guy.lt> (document.domain=<http://www.guy.lt>) to get property Window.document from <http://www.guy.lt> (document.domain has not been set).
如果这不是错误,那么如何解释这种行为?(或至少是错误消息)当然,如何解决它?
另一个奇怪的事情是:
debug.log('0');
document.domain = 'guy.lt';
debug.log('1');
document.domain = 'wwww.guy.lt';
debug.log('2');
debug.log('2')
永远不会触发。但是,console
中没有错误。脚本只是停止执行。
我无法根据您的问题推断您做错了什么,但要启用跨域脚本,您必须document.domain
设置为域的相同公共部分。还相关:
-
如果一侧使用
foo.guy.lt
而另一侧使用bar.guy.lt
则必须在两侧设置document.domain = "guy.ly"
。 -
如果将
document.domain
设置为guy.lt
则实际域必须guy.lt
本身或guy.lt
的子域。您不能编造(子)域名。 -
你总是必须显式指定
document.domain
的值,即使该值是实际的域本身。 -
您永远无法将
document.domain
更改回更具体的子域。因此,如果实际域是www.guy.lt
,则可以将document.domain
更改为guy.lt
。但是,在此更改之后,您无法将其更改回www.guy.lt
.
例子:
// 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
设置为相同的值时,才允许通过document.domain
进行跨网域访问。 这是一项必要的安全措施;否则something.company.com
可以将document.domain
设置为company.com
并从company.com
中读取内容。 实际上,只有当company.com
通过将document.domain
设置为 company.com
来明确选择加入时,它才能做到这一点。
相关文章:
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 文档就绪提供了错误的选择器高度
- 未捕获的语法错误:无法在“文档”上执行“查询选择器”
- 是否存在Javascript Liferay Service库的文档?如何处理错误情况
- 使用mongoose保存多个文档时的错误处理
- Rect.map():文档是否错误
- 如何防止加载外部资源,同时防止“在'文档'上执行'写入'失败”错误
- Meteor Update集合-未捕获错误:不允许.不受信任的代码只能通过ID更新文档.[403]
- Javascript错误文档.getElementById('x').style.display=
- Foundation 5可能的错误:未捕获类型错误:层必须是文档节点Foundation.min.js:8
- 未捕获的引用错误:未在Javascript(Chrome控制台)中定义文档
- 角度错误:[$rootScope:inprog]$已在文档上应用.单击()
- 在 javascript 中创建 xml 文档显示错误
- IE9 中的“Acecss 拒绝内容文档”错误与 goog.net.IFrameIO
- 我有错误文档.注册元素未被细化
- 活动类添加到菜单中的错误文档对象
- Jquery时的响应和错误文档
- Javascript错误-文档.getElementsById不是一个函数
- W3C错误:文档类型不允许元素X在这里;缺少一个Y开始标签
- 未捕获的类型错误:文档.getElementById不是一个函数