Google 趋势嵌入和 X-Frame-Options
Google Trends embedding and X-Frame-Options
尝试使用来自 Google Trends 的嵌入脚本导致 Chrome 下出现以下错误。
Refused to display 'url' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
我已将脚本放入 index.html
的正文中,并将其托管在本地和外部服务器上。
据我所知,它会停止 'clickjacking',但是 Google 提供的脚本无法在他们自己的浏览器上运行似乎很奇怪。 Firefox 工作正常。
这是 Google 趋势嵌入无法与 Google 自己的产品一起使用的基本问题,还是我的服务器设置有问题?
很久以前我在处理基于 spring 的项目时就遇到了同样的问题。我可以预先告诉您一件事,这不是 google 趋势的问题,您需要通过稍微更改您的请求来解决它。
对于您的请求 headers,您需要发送一个额外的 header X-Frame-Options
并将其值设置为 SAMEORIGIN
。
我不提供详细信息,因为已经讨论过类似的问题here。
希望对您有所帮助!!!
更新 1:
不要对 X-Frame-Options
和您要嵌入的框架感到困惑。当您尝试在网页上嵌入框架时,浏览器会检查您是否允许 SAMEORIGIN
。默认情况下,它未启用,因此您会收到错误消息。但是在您的 back-end 代码中,如果您配置的方式是针对每个请求,您的框架将 header 添加为 X-Frame-Options
,值为 SAMEORIGIN
然后浏览器将允许它。
请注意,SAMEORIGIN
将允许您网站上的每个网页,这可能会导致安全问题。所以另一种选择是,您只需使用 ALLOW-FROM 标签设置 Google 趋势网站,而不是 sameorigin
。
(根据您的评论,您正在使用 Laravel 框架(我从未使用过 php),this link 可能对您有用。或者您可以 google "how to set x-frame-options sameorigin in laravel".
这是因为您的浏览器设置为阻止第三方 cookie。启用第三方 cookie,嵌入式 Google Trends iframe 将起作用。
如果您仔细查看失败的 iframe 请求,它包含此 header:
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
header 链接到 this page 的解释如下:
In some situations, the cookies we use to secure and authenticate your Google Account and store your preferences may be served from a different domain than the website you're visiting. This may happen, for example, if you visit websites with Google +1 buttons.
Some browsers require third party cookies to use the P3P protocol to state their privacy practices. However, the P3P protocol was not designed with situations like these in mind. As a result, we've inserted a link into our cookies that directs users to a page where they can learn more about the privacy practices associated with these cookies.
尝试使用来自 Google Trends 的嵌入脚本导致 Chrome 下出现以下错误。
Refused to display 'url' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
我已将脚本放入 index.html
的正文中,并将其托管在本地和外部服务器上。
据我所知,它会停止 'clickjacking',但是 Google 提供的脚本无法在他们自己的浏览器上运行似乎很奇怪。 Firefox 工作正常。
这是 Google 趋势嵌入无法与 Google 自己的产品一起使用的基本问题,还是我的服务器设置有问题?
很久以前我在处理基于 spring 的项目时就遇到了同样的问题。我可以预先告诉您一件事,这不是 google 趋势的问题,您需要通过稍微更改您的请求来解决它。
对于您的请求 headers,您需要发送一个额外的 header X-Frame-Options
并将其值设置为 SAMEORIGIN
。
我不提供详细信息,因为已经讨论过类似的问题here。
希望对您有所帮助!!!
更新 1:
不要对 X-Frame-Options
和您要嵌入的框架感到困惑。当您尝试在网页上嵌入框架时,浏览器会检查您是否允许 SAMEORIGIN
。默认情况下,它未启用,因此您会收到错误消息。但是在您的 back-end 代码中,如果您配置的方式是针对每个请求,您的框架将 header 添加为 X-Frame-Options
,值为 SAMEORIGIN
然后浏览器将允许它。
请注意,SAMEORIGIN
将允许您网站上的每个网页,这可能会导致安全问题。所以另一种选择是,您只需使用 ALLOW-FROM 标签设置 Google 趋势网站,而不是 sameorigin
。
(根据您的评论,您正在使用 Laravel 框架(我从未使用过 php),this link 可能对您有用。或者您可以 google "how to set x-frame-options sameorigin in laravel".
这是因为您的浏览器设置为阻止第三方 cookie。启用第三方 cookie,嵌入式 Google Trends iframe 将起作用。
如果您仔细查看失败的 iframe 请求,它包含此 header:
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
header 链接到 this page 的解释如下:
In some situations, the cookies we use to secure and authenticate your Google Account and store your preferences may be served from a different domain than the website you're visiting. This may happen, for example, if you visit websites with Google +1 buttons.
Some browsers require third party cookies to use the P3P protocol to state their privacy practices. However, the P3P protocol was not designed with situations like these in mind. As a result, we've inserted a link into our cookies that directs users to a page where they can learn more about the privacy practices associated with these cookies.