google search results in iframe alternative

2019-01-26 10:29发布

问题:

I don't think it's possible from what I've read, but wanted to see if anyone else was in a similar situation and found a more elegent solution to this problem.

Basically I have a site I am building, nothing fancy, which consists of a header section, and then one big iframe to display the content of the page in. I know, I know, iframe are generally looked upon with displeasure, but for my needs, it works wonders.

My issue, is that in the header of the page, I have a simple google search box (basically just an html form), and have set the target as my iframe. Obviously when searching for anything, the results should show up in the iframe, however, all i get is a message saying this content can't be displayed in an iframe. This makes sense and im sure it is of googles design not to allow this kind of practice.

For me, this would be the most ideal situation, and was wondering if anyone knew of a way to display the search results within my iframe?

I have also looked at possibly displaying a lightbox, or similar popup box, with an ajax request to display the google page, but have thusfar been unsuccessful.

回答1:

You won't be able to use any kind of frame anymore as Google obviously put an end to that by blocking frames altogether. Your only solution is to use the custom search API and then parse and display the results yourself.