iframe被拒绝_IFRAME权限被拒绝的解决方案

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 。 标头可以具有NONESAMEORIGIN值,并且将x-frame-optionsSAMEORIGIN解决我的问题!

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内容。

翻译自: https://davidwalsh.name/iframe-permission-denied

iframe被拒绝

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值