如何在谷歌搜索结果页面中嵌入iframe

时间:2022-09-13 09:48:48

For whatever reason, that's not important, i'm trying to combine google shopping with another page via an iframe.

不管出于什么原因,这并不重要,我正在尝试将谷歌与另一页通过iframe进行合并。

I've tried the approach proposed here, consisting of embedding a google custom search query in an iframe, but google custom search does not allow access to the shopping tab.

我已经尝试了这里提出的方法,包括在iframe中嵌入一个谷歌自定义搜索查询,但是谷歌自定义搜索不允许访问购物选项卡。

I figured, if you can't embed Google, embed yourself in it. So I proceeded to inject some jQuery in the page

我想,如果你不能嵌入谷歌,那就把自己嵌入其中。所以我开始在页面中注入一些jQuery。

var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();

clean up the google shopping search results page to what I needed, namely the html inside the div#search

清理谷歌购物搜索结果页面到我需要的地方,即div#搜索中的html

jQuery(function($) {$('#search').show().parentsUntil('body').andSelf().siblings().hide();});

Create an iframe and inject it:

创建一个iframe并注入它:

var iframe = document.createElement('iframe')
iframe.src="http://example.com"
iframe.width="100%";
iframe.height="500";
iframe.style="visibility:visible";
document.body.appendChild(iframe)

Only problem is the iframe doesn't load the contents of the page and in turn is blank. If you try the above snippet in any other page, it works. It seems like Google is blocking the iframe from loading. How can I get around that?

唯一的问题是iframe没有加载页面的内容,反过来又是空白的。如果您在任何其他页面中尝试上述代码片段,它都可以工作。看来谷歌阻止了iframe加载。我怎么能避开呢?

3 个解决方案

#1


3  

Google seems not to work using an iframe... Even if you are not using JS. What you should use instead is the Google Custom Search API, wich allows you to create a custom search engine. You just have to enter an example website, change the Option to Search all the web. and remove your entered website again. To create a custom Search engine you'll need a google account. Start here.

谷歌似乎不能使用iframe…即使不使用JS。您应该使用的是谷歌自定义搜索API,该API允许您创建自定义搜索引擎。您只需输入一个示例网站,更改搜索所有web的选项。并再次删除您输入的网站。要创建自定义搜索引擎,您需要一个谷歌帐户。从这里开始。

#2


2  

When I run that code, the following error is reported in my console:

当我运行该代码时,在我的控制台中报告如下错误:

VM259:7 Mixed Content: The page at 'https://www.google.co.uk/?gws_rd=ssl' was loaded over HTTPS, but requested an insecure resource 'http://example.com/'. This request has been blocked; the content must be served over HTTPS.

VM259:7混合内容:https://www.google.co.uk/?gws_rd=ssl'是通过HTTPS加载的,但是请求一个不安全的资源“http://example.com/”。该请求已被阻止;内容必须通过HTTPS提供。

Changing it to an HTTPS URL:

将其更改为HTTPS URL:

var iframe = document.createElement('iframe')
iframe.src="https://example.com"
iframe.width="100%";
iframe.height="500";
iframe.style="visibility:visible";
document.body.appendChild(iframe)

… makes it work fine (albeit it tucked behind the logo):

(尽管它隐藏在商标后面):

如何在谷歌搜索结果页面中嵌入iframe

#3


2  

Tnx for @Quentins comment.

Tnx @Quentins评论。

UPD:

乌利希期刊指南:

Embedding code to google website:

将代码嵌入谷歌网站:

In general you can't embed code for page that you don't own.

一般来说,你不能在你不拥有的页面中嵌入代码。

if user opens your website and open another tab with google or your website opens another tab with google, your website doesn't have access to google website source code/context and you can't affect on google website, because there are completely isolated from each other.

如果用户打开你的网站,用谷歌打开另一个标签,或者你的网站用谷歌打开另一个标签,你的网站没有访问谷歌网站的源代码/上下文,你不能影响谷歌网站,因为它们是完全隔离的。

Seems your actions for cleaning results and embedding your iframe in google page you made in your browser console. That changes affect only locally for your browser and doesn't affect for any other users that open google website.

似乎你的行动清洁结果和嵌入你的iframe谷歌页你在你的浏览器控制台。这种变化只对浏览器本地产生影响,对打开谷歌网站的其他用户没有影响。

Possible solutions:

可能的解决方式:

Actually, you can embed some code to other pages, but you need to use:

实际上,您可以将一些代码嵌入到其他页面,但是您需要使用:

  • Browser extensions (too complicated, because user need to install your extension for browser)
  • 浏览器扩展(太复杂了,因为用户需要为浏览器安装扩展)
  • XSS/other vulnerables (that's almost impossible for google search website)
  • XSS/其他漏洞(谷歌搜索网站几乎不可能)

Embedding google to your page:

将谷歌嵌入到您的页面:

You can't embed iframe from google because of x-frame-options header in http response for google.com. There is no good workaround, sorry.

你不能从谷歌中嵌入iframe,因为google。com的http响应中的x帧选项头。不好意思,没有什么好办法。

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

可以使用x帧选项HTTP响应头来指示是否应该允许浏览器在、

如何在谷歌搜索结果页面中嵌入iframe

#1


3  

Google seems not to work using an iframe... Even if you are not using JS. What you should use instead is the Google Custom Search API, wich allows you to create a custom search engine. You just have to enter an example website, change the Option to Search all the web. and remove your entered website again. To create a custom Search engine you'll need a google account. Start here.

谷歌似乎不能使用iframe…即使不使用JS。您应该使用的是谷歌自定义搜索API,该API允许您创建自定义搜索引擎。您只需输入一个示例网站,更改搜索所有web的选项。并再次删除您输入的网站。要创建自定义搜索引擎,您需要一个谷歌帐户。从这里开始。

#2


2  

When I run that code, the following error is reported in my console:

当我运行该代码时,在我的控制台中报告如下错误:

VM259:7 Mixed Content: The page at 'https://www.google.co.uk/?gws_rd=ssl' was loaded over HTTPS, but requested an insecure resource 'http://example.com/'. This request has been blocked; the content must be served over HTTPS.

VM259:7混合内容:https://www.google.co.uk/?gws_rd=ssl'是通过HTTPS加载的,但是请求一个不安全的资源“http://example.com/”。该请求已被阻止;内容必须通过HTTPS提供。

Changing it to an HTTPS URL:

将其更改为HTTPS URL:

var iframe = document.createElement('iframe')
iframe.src="https://example.com"
iframe.width="100%";
iframe.height="500";
iframe.style="visibility:visible";
document.body.appendChild(iframe)

… makes it work fine (albeit it tucked behind the logo):

(尽管它隐藏在商标后面):

如何在谷歌搜索结果页面中嵌入iframe

#3


2  

Tnx for @Quentins comment.

Tnx @Quentins评论。

UPD:

乌利希期刊指南:

Embedding code to google website:

将代码嵌入谷歌网站:

In general you can't embed code for page that you don't own.

一般来说,你不能在你不拥有的页面中嵌入代码。

if user opens your website and open another tab with google or your website opens another tab with google, your website doesn't have access to google website source code/context and you can't affect on google website, because there are completely isolated from each other.

如果用户打开你的网站,用谷歌打开另一个标签,或者你的网站用谷歌打开另一个标签,你的网站没有访问谷歌网站的源代码/上下文,你不能影响谷歌网站,因为它们是完全隔离的。

Seems your actions for cleaning results and embedding your iframe in google page you made in your browser console. That changes affect only locally for your browser and doesn't affect for any other users that open google website.

似乎你的行动清洁结果和嵌入你的iframe谷歌页你在你的浏览器控制台。这种变化只对浏览器本地产生影响,对打开谷歌网站的其他用户没有影响。

Possible solutions:

可能的解决方式:

Actually, you can embed some code to other pages, but you need to use:

实际上,您可以将一些代码嵌入到其他页面,但是您需要使用:

  • Browser extensions (too complicated, because user need to install your extension for browser)
  • 浏览器扩展(太复杂了,因为用户需要为浏览器安装扩展)
  • XSS/other vulnerables (that's almost impossible for google search website)
  • XSS/其他漏洞(谷歌搜索网站几乎不可能)

Embedding google to your page:

将谷歌嵌入到您的页面:

You can't embed iframe from google because of x-frame-options header in http response for google.com. There is no good workaround, sorry.

你不能从谷歌中嵌入iframe,因为google。com的http响应中的x帧选项头。不好意思,没有什么好办法。

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

可以使用x帧选项HTTP响应头来指示是否应该允许浏览器在、

如何在谷歌搜索结果页面中嵌入iframe