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

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


当前回答

当我尝试在iframe中嵌入moodle 2时,我也有同样的问题,解决方案是站点管理►安全►HTTP安全并检查允许框架嵌入

其他回答

<form target="_parent" ... />

根据Kevin Vella的想法,我尝试在PayPal的按钮生成器生成的表单元素上使用上述方法。为我工作,这样贝宝不会在一个新的浏览器窗口/标签打开。

更新

这里有一个例子:

在今天(01-19-2021)生成按钮时,PayPal自动在表单元素上包含target="_top",但如果这对您的上下文不起作用,请尝试不同的目标值。我建议_parent——至少当我使用这个PayPal按钮时,它是有效的。

有关更多信息,请参阅表单目标值。

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_parent">
  <input type="hidden" name="cmd" value="_xclick">
  <input type="hidden" name="business" value="name@email.com">
  <input type="hidden" name="lc" value="US">
  <input type="hidden" name="button_subtype" value="services">
  <input type="hidden" name="no_note" value="0">
  <input type="hidden" name="currency_code" value="USD">
  <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
  <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

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.

我在mediawiki上遇到了同样的问题,这是因为服务器出于安全原因拒绝将页面嵌入到iframe中。

我写了

$wgEditPageFrameOptions = "SAMEORIGIN"; 

导入mediawiki PHP配置文件。

希望能有所帮助。

我不确定这有什么关系,但我想出了一个变通办法。在我的网站上,我想在一个包含加载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";
}


?>

希望这能有所帮助。

这就是解决办法!!

FB.Event.subscribe('edge.create', function(response) {
    window.top.location.href = 'url';
});

这是唯一适用于facebook应用的方法!