Reputation: 428
I am trying to create a custom search for a website. I currently work as a web dev maintaining several sites. It was recently brought to my attention that there was a problem on the search page not generating results properly. I looked into it and found out that the person who originally created the site copied it from an existing site, so the google search string (they call it cx in the google docs) was pointing to the wrong one (the olde site). So I went to google and created a new Custom Search Engine and just replaced the old cx value. All the code Is the same except for this. I am using the JavaScript provide to you by google and not the API directly. The JavaScript generates an iframe in a predetermined div and embeds the search results in said Iframe. The problem is that google is sending a X-frame-options same origins response. I checked other sites and the only difference that these sites have is the CX stirng. All of their search functionality works just fine. How do I fix this so the response is different?
The code as provided by Google:
<script>
(function() {
var cx = '011369833985782852522:6v8rougwxxa';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
Upvotes: 1
Views: 813
Reputation: 595
Google CSE does not support displaying results in an IFRAME anymore (see https://support.google.com/customsearch/answer/2641279?hl=en).
You will have to switch to Custom Search Elements (https://developers.google.com/custom-search/docs/js/cselement-devguide).
Upvotes: 1
Reputation: 11
I am having the exact same problem, I could not find a solution that worked for me, as I am using a joomla website and I do not have much control of the codes.
I found two possible solutions, see if one of them can help you:
iframe src="http://xxxxxxxxxxxxsxxxxx&output=embed"
Header always unset X-Frame-Options
At the end, I just created a custom module and added the code that Google provided for my website in http://www.google.com/cse
I can't be sure if one of them will actually work as I wasn't able to test it, but I wanted to at least share what I could find in my researches, maybe it can help you.
Good luck!
Upvotes: 0