How can you insert an iframe on a Google search results page

For some reason this is not important, I'm trying to combine Google purchases with another page through an iframe.

I tried the suggested approach here , consisting of embedding a Google custom search query in an iframe, but Google Custom Search does not allow access to the shopping tab.

I realized that if you can’t implement Google, insert yourself into it. So I started introducing some jQuery on the page

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(); 

clear the google search results page according to the search schedule with what I need, namely the html inside the div # search

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

Create an iframe and enter it:

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

The only problem is that the iframe does not load the contents of the page and, in turn, is empty. If you try the above snippet on any other page, it works. It looks like Google is blocking the iframe from loading. How can I get around this?

+5
source share
3 answers

Google does not seem to work using iframe ... Even if you are not using JS. Instead, you should use a custom search API that allows you to create a custom search system. You just need to enter an example website, change the search option all over the Internet. and delete the entered website again. To create a custom search engine, you need a google account. Start here .

+3
source

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

VM259: 7 Mixed Content: The https://www.google.co.uk/?gws_rd=ssl 'page was loaded via HTTPS but requested the unsafe resource' http://example.com/ '. This request is blocked; content must be transmitted via HTTPS.

Changing it to an 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 (although it is stuck behind the logo):

screenshot

+2
source

Tnx for @Quentins comment.

UPD:

Enter the code on google:

In general, you cannot embed code for a page that you do not have.

if a user opens your site and opens another tab using Google, or another tab opens on your website from Google, your site does not have access to the source code / context of the google website and you cannot influence the google website, because there are completely isolated from each other.

It seems your steps to clear the results and embed your iframe on the google page you made in your console. These changes affect only your browser locally and do not affect other users who open the Google site.

Possible solutions:

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

  • Browser extensions (too complicated because the user needs to install a browser extension)
  • XSS / other vulnerabilities (which is almost impossible for google search site)

Attach google to your page:

You cannot embed an iframe from Google due to x-frame-options in the http response for google.com. Unpleasant workaround, sorry.

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

enter image description here

+2
source

Source: https://habr.com/ru/post/1245763/


All Articles