Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Paul Murphy
Paul Murphy
6,162 Points

Google custom search - results only

Hi Guys,

Asked this question a few times now but haven't had a definitive answer as yet.

I want to implement google CSE on my site (www.pressure-vessel-steels.co.za)

Using the results only option, placing the following js in my index file for example:

<script> (function() { var cx = '007920249510402107771:vklelu7qtb0'; 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); })(); </script>

I placed the script above just after the opening <body> tag. With a simple <form> where I want the search box to appear like this:

<form class="group" id="searchbox_007920249510402107771:vklelu7qtb0"   action="results.html" method="get"> 
<input value="007920249510402107771:vklelu7qtb0" name="cx" type="hidden"/> <input value="FORID:11" name="cof" type="hidden"/>
<input type="text" name="s" style="width:220px;"id="s" value="search..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/> 
<input value="Go" name="sa" type="submit"/> 
</form>

then finally in my results.html file I place the html string inside a <div>

<gcse:searchresults-only></gcse:searchresults-only>

So far no results.... any help would be appreciated

Is the CSE no longer used on your site? I went there, but didn't see it.

Here is my implementation on a demo site: http://vision-demo-server.tech/mocoil/

If this looks like what you need, let me know and I'll post an answer.

2 Answers

Samuel Rueby
Samuel Rueby
22,538 Points

Any errors in your browser's console?

Paul Murphy
Paul Murphy
6,162 Points

Not that I can see, I have put the search bar live on the site now and still no console errors.... could you take a look if you have time?

www.pressure-vessel-steels.co.za

You could try search terms "Chrome" or "stainless" for example.

Samuel Rueby
Samuel Rueby
22,538 Points

I think the script should be included on all pages because the search box appears to be on all pages. I only found the script on the home page.

I couldn't find <gcse:searchresults-only>/gcse:searchresults-only in result.html.