iframe被拒绝

    技术2022-07-11  133

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

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

    iframe被拒绝

    相关资源:完美解决iframe跨域问题
    Processed: 0.010, SQL: 9