12

当我尝试检查 chrome 中的元素时出现错误:

拒绝在框架中显示“ http://www.samplesite.com/ ”,因为它设置'X-Frame-Options''SAMEORIGIN'

'X-Frame-Options'如何在网站必须在其中显示的 iframe 中显示网站 'SAMEORIGIN'

我尝试在谷歌上搜索,但找不到任何合适的解决方案,有些仅适用于 asp.net。

4

3 回答 3

6

网络服务器配置,

对我来说,我使用 nginx.conf

找到add_header X-Frame-Options SAMEORIGIN;并将其更改为add_header X-Frame-Options "ALLOWALL";

您的 Web 服务器发送标头并阻止内容。您可能应该将此设置更改为允许来自同一来源。

于 2014-07-30T06:07:10.933 回答
-1

要解决此错误:

截图中提到的问题.

.htaccess您只需根据要提供的访问级别将此代码放在文件中:

  1. X-Frame-Options: deny
  2. X-Frame-Options: sameorigin
  3. X-Frame-Options: "allow-from https://example.com/"
于 2019-01-14T14:13:07.417 回答
-4

我也有类似的问题。将我的网页加载到另一个网站上的 iframe 时出现此错误: 拒绝在框架中显示“ https://mywebsite.com ”,因为它将“X-Frame-Options”设置为“sameorigin”。

我已经解决了使用这个允许 IFrame 绕过 X-Frame-Options:deny/sameorigin 响应标头的 Web 组件的问题。 https://github.com/niutech/x-frame-bypass

要测试它,只需将此代码保存在index.html文件中,并将可以从上述 Github 存储库下载的文件x-frame-bypass.js放在同一目录中。

由于 Safari 不支持自定义的内置元素,我添加了一个额外的脚本来允许支持。 https://www.chromestatus.com/feature/4670146924773376

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>X-Frame-Bypass For Global CI calendar</title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            overflow: hidden;
        }
        iframe {
            display: block;
            width: calc(100% - 40px);
            height: calc(100% - 40px);
            margin: 20px;
            border: 0;
        }

    </style>

    <!-- To bypass the CROSS ORIGIN Resource issue -->
        <script src="x-frame-bypass.js" type="module"></script>

    <!-- Support Customized built-in elements for Safari-->
        <script src="https://unpkg.com/@ungap/custom-elements-builtin"></script>

</head>
<body>
    <iframe is="x-frame-bypass" src="https://www.link_to_any_website.com"></iframe>
</body>
</html>
于 2019-01-22T14:44:14.273 回答