我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。

是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?


当前回答

I came across this issue when running a wordpress web site. I tried all sorts of things to fix it and wasn't sure how, ultimately the issue was because I was using DNS forwarding with masking, and the links to external sites were not being addressed properly. i.e. my site was hosted at http://123.456.789/index.html but was masked to run at http://somewebSite.com/index.html. When i entered http://123.456.789/index.html in the browser clicking on those same links resulted in no X-frame-origins issues in the JS console, but running http://somewebSite.com/index.html did. In order to properly mask you must add your host's DNS name servers to your domain service, i.e. godaddy.com should have name servers of example, ns1.digitalocean.com, ns2.digitalocean.com, ns3.digitalocean.com, if you were using digitalocean.com as your hosting service.

其他回答

有一个Chrome插件,删除头条目(仅供个人使用):

https://chrome.google.com/webstore/detail/ignore-x-frame-headers/gleekbfjekiniecknbkamfmkohkpodhe/reviews

我使用的是Tomcat 8.0.30,没有一个建议对我有效。当我们希望更新X-Frame-Options并将其设置为允许时,以下是我如何配置允许嵌入iframes:

进入Tomcat conf目录,编辑web.xml文件 添加下面的过滤器:

<filter>
            <filter-name>httpHeaderSecurity</filter-name>
            <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
                   <init-param>
                           <param-name>hstsEnabled</param-name>
                           <param-value>true</param-value>
                   </init-param>
                   <init-param>
                           <param-name>antiClickJackingEnabled</param-name>
                           <param-value>true</param-value>
                   </init-param>
                   <init-param>
                           <param-name>antiClickJackingOption</param-name>
                           <param-value>ALLOW-FROM</param-value>
                   </init-param>
            <async-supported>true</async-supported>
       </filter>

       <filter-mapping>
                   <filter-name>httpHeaderSecurity</filter-name>
                   <url-pattern>/*</url-pattern>
                   <dispatcher>REQUEST</dispatcher>
       </filter-mapping> 

重启Tomcat服务 使用iFrame访问资源。

I came across this issue when running a wordpress web site. I tried all sorts of things to fix it and wasn't sure how, ultimately the issue was because I was using DNS forwarding with masking, and the links to external sites were not being addressed properly. i.e. my site was hosted at http://123.456.789/index.html but was masked to run at http://somewebSite.com/index.html. When i entered http://123.456.789/index.html in the browser clicking on those same links resulted in no X-frame-origins issues in the JS console, but running http://somewebSite.com/index.html did. In order to properly mask you must add your host's DNS name servers to your domain service, i.e. godaddy.com should have name servers of example, ns1.digitalocean.com, ns2.digitalocean.com, ns3.digitalocean.com, if you were using digitalocean.com as your hosting service.

我有这个问题,并解决了它编辑httd.conf

<IfModule headers_module>
    <IfVersion >= 2.4.7 >
        Header always setifempty X-Frame-Options GOFORIT
    </IfVersion>
    <IfVersion < 2.4.7 >
        Header always merge X-Frame-Options GOFORIT
    </IfVersion>
</IfModule>

我把SAMEORIGIN改成了GOFORIT 并重新启动服务器

令人惊讶的是,这里没有人提到Apache服务器的设置(*.conf文件)或.htaccess文件本身是导致这个错误的原因。搜索你的。htaccess或Apache配置文件,确保你没有以下设置为DENY:

报头总是设置X-Frame-Options DENY

将其更改为SAMEORIGIN,使事情按预期工作:

报头总是设置X-Frame-Options SAMEORIGIN