iframe被拒绝
I was recently rolling my own AJAX upload script, posting a form to a hidden IFRAME and using the load event to know when the upload was complete. When the upload completed, I wanted to access the IFRAME content so I could verify that the upload completed successfully. Surprisingly I ran into the following JavaScript error:
最近,我正在滚动自己的AJAX上传脚本,将表单发布到隐藏的IFRAME中,并使用load事件知道何时完成上传。 上传完成后,我想访问IFRAME内容,以便可以验证上传成功完成。 令人惊讶的是,我遇到了以下JavaScript错误:
Error: Permission denied to access property 'document'
If you were using jQuery, you may see this error instead:
如果您使用的是jQuery,则可能会看到此错误:
Error: Permission denied to access property 'nodeType'
This confused me because I knew that my IFRAME was accessing an address on the same host, including protocol. After pulling my hair out and sending a plea for ideas on Twitter, Daniel Buchner mentioned a server-side header that I needed to adjust to allow for accessing that frame's nodes: x-frame-options
. The header can have values of NONE
or SAMEORIGIN
, and setting the x-frame-options
to SAMEORIGIN
fixed my issue!
这让我感到困惑,因为我知道我的IFRAME正在访问同一主机上的地址,包括协议。 在拔出头发并在Twitter上发表想法请求后,Daniel Buchner提到了服务器端标头,我需要对其进行调整以允许访问该框架的节点: x-frame-options
。 标头可以具有NONE
或SAMEORIGIN
值,并且将x-frame-options
为SAMEORIGIN
解决我的问题!
If you continue seeing a "Permission Denied" error, it's very possible you're trying to do a cross-origin request, and that simply wont allow you access to the IFRAME content, unless a CORS configuration has been added.
如果您继续看到“权限被拒绝”错误,则很可能是您尝试进行跨域请求,并且除非您添加了CORS配置,否则根本就不允许您访问IFRAME内容。
iframe被拒绝