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

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


当前回答

我有这个问题,并解决了它编辑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 并重新启动服务器

其他回答

添加一个

  target='_top'

到我的链接在facebook标签为我解决了这个问题…

我有一个类似的问题,我试图在一个iframe中显示我们自己网站的内容(作为一个带有Colorbox的lightbox样式的对话框),并且我们在源服务器上有一个服务器范围的“X-Frame-Options SAMEORIGIN”报头,防止它加载到我们的测试服务器上。

这似乎没有被记录在任何地方,但如果你可以编辑你试图iframe的页面(例如。,它们是你自己的页面),简单地发送另一个X-Frame-Options报头,任何字符串都禁用SAMEORIGIN或DENY命令。

如。对于PHP,放入

<?php
    header('X-Frame-Options: GOFORIT'); 
?>

在页面的顶部会使浏览器将两者结合起来,从而导致页眉为

X-Frame-Options SAMEORIGIN, GOFORIT

...并允许您在iframe中加载页面。当初始的SAMEORIGIN命令设置在服务器级别时,这似乎可以工作,并且您希望在逐页情况下重写它。

祝你一切顺利!

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.

唯一一个有一堆答案的问题。欢迎来到这个指南,我希望我在最后期限那天晚上10:30为它工作时能有这个指南……facebook在canvas应用上做了一些奇怪的事情,好吧,你已经被警告过了。如果你还在这里,你有一个Rails应用程序将出现在Facebook Canvas后面,那么你将需要:

Gemfile:

gem "rack-facebook-signed-request", :git => 'git://github.com/cmer/rack-facebook-signed-request.git'

配置/ facebook.yml

facebook:
  key: "123123123123"
  secret: "123123123123123123secret12312"

配置/ application.rb

config.middleware.use Rack::Facebook::SignedRequest, app_id: "123123123123", secret: "123123123123123123secret12312", inject_facebook: false

配置/初始化/ omniauth.rb

OmniAuth.config.logger = Rails.logger
SERVICES = YAML.load(File.open("#{::Rails.root}/config/oauth.yml").read)
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, SERVICES['facebook']['key'], SERVICES['facebook']['secret'], iframe:   true
end

application_controller.rb

before_filter :add_xframe
def add_xframe
  headers['X-Frame-Options'] = 'GOFORIT'
end

你需要一个控制器来调用Facebook的画布设置,我使用/canvas/,并使路由到这个应用程序的主SiteController:


class SiteController < ApplicationController
  def index
    @user = User.new
  end
  def canvas
    redirect_to '/auth/failure' if request.params['error'] == 'access_denied'
    url = params['code'] ? "/auth/facebook?signed_request=#{params['signed_request']}&state=canvas" : "/login"
    redirect_to url
  end
  def login
  end
end

login.html.erb


<% content_for :javascript do %>
  var oauth_url = 'https://www.facebook.com/dialog/oauth/';
  oauth_url += '?client_id=471466299609256';
  oauth_url += '&redirect_uri=' + encodeURIComponent('https://apps.facebook.com/wellbeingtracker/');
  oauth_url += '&scope=email,status_update,publish_stream';
console.log(oauth_url);
  top.location.href = oauth_url;
<% end %>

来源

配置我认为来自omniauth的例子。 宝石文件(这是关键!!)来自:slideshare things i learned… 这个堆栈问题有整个Xframe的角度,所以你会得到一个空白,如果 你不需要把这个头文件放到应用控制器中。 我的男人@rafmagana写了这个heroku指南,现在你可以用这个答案来做轨道,也可以用巨人的肩膀走路。

我不确定这有什么关系,但我想出了一个变通办法。在我的网站上,我想在一个包含加载URL的iframe的模态窗口中显示链接。

我所做的是,我将链接的点击事件链接到这个javascript函数。所有这些操作都是向一个PHP文件发出请求,该文件在决定是在模式窗口中加载URL还是重定向之前,检查URL头中的X-FRAME-Options。

函数如下:

  function opentheater(link, title){
        $.get( "url_origin_helper.php?url="+encodeURIComponent(link), function( data ) {
  if(data == "ya"){
      $(".modal-title").html("<h3 style='color:480060;'>"+title+"&nbsp;&nbsp;&nbsp;<small>"+link+"</small></h3>");
        $("#linkcontent").attr("src", link);
        $("#myModal").modal("show");
  }
  else{
      window.location.href = link;
      //alert(data);
  }
});


        }

下面是检查它的PHP文件代码:

<?php
$url = rawurldecode($_REQUEST['url']);
$header = get_headers($url, 1);
if(array_key_exists("X-Frame-Options", $header)){
    echo "nein";
}
else{
    echo "ya";
}


?>

希望这能有所帮助。