我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。
是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?
我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止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.
其他回答
我在mediawiki上遇到了同样的问题,这是因为服务器出于安全原因拒绝将页面嵌入到iframe中。
我写了
$wgEditPageFrameOptions = "SAMEORIGIN";
导入mediawiki PHP配置文件。
希望能有所帮助。
如果你在YouTube视频中遇到这个错误,不要使用完整的url,而是使用共享选项中的嵌入url。它看起来像http://www.youtube.com/embed/eCfDxZxTBW4
您还可以更换手表吗?v= with embed/ so http://www.youtube.com/watch?v=eCfDxZxTBW4变成http://www.youtube.com/embed/eCfDxZxTBW4
<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>
唯一一个有一堆答案的问题。欢迎来到这个指南,我希望我在最后期限那天晚上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指南,现在你可以用这个答案来做轨道,也可以用巨人的肩膀走路。
唯一真正的答案,如果你不控制你想在iframe中的源的头,就是代理它。让服务器充当客户端,接收源,去除有问题的头,如果需要添加CORS,然后ping您自己的服务器。
还有一个解释如何编写这样一个代理的答案。这并不难,但我相信以前一定有人这么做过。只是因为某些原因,很难找到它。
我终于找到了一些资料来源:
https://github.com/Rob--W/cors-anywhere/#documentation
^者优先。如果你需要很少使用,我认为你可以使用他的heroku应用程序。否则,这是在你自己的服务器上运行它的代码。注意限制是什么。
whateverorigin.org
^第二选择,但相当古老。应该是python中的新选择:https://github.com/Eiledon/alloworigin
还有第三种选择:
http://anyorigin.com/
这似乎允许一些免费使用,但如果你不付钱,使用一些不确定的数量,你就会被列入公众的耻辱名单,只有在你付钱的情况下,你才能被删除……