拒绝在iframe中显示网站,X-Frame-Options为'SAMEORIGIN'

问题描述 投票:4回答:4

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

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

如何在iframe中显示一个网站,其中网站的“X-Frame-Options”为“SAMEORIGIN”?

我尝试在谷歌搜索,但我找不到一些解决方案,一些仅适用于asp.net。

iframe x-frame-options
4个回答
3
投票

Web服务器conf,

对我来说,我使用nginx.conf

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

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


0
投票

要解决此错误:

.

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

  1. X-Frame-Options: deny
  2. X-Frame-Options: sameorigin
  3. X-Frame-Options: "allow-from https://example.com/"

0
投票

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

我已经解决了使用这个允许IFrame绕过X-Frame-Options的web组件:deny / sameorigin响应头。 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>

0
投票

有些网站阻止你这样做。您可以做的是使用第三方工具,通过使用代理来解决它:https://cors.io

虽然,这是一个冒险的解决方案

© www.soinside.com 2019 - 2024. All rights reserved.