Google Custom Search Engine

To add a Google Custom Search Engine to your site, you need to create a gadget. Below you will see the code for the CSE I use on this site. Just copy the code, change the highlighted part to the code for your CSE (use V1 code and specify protocol relative), store it somewhere online as an .xml file and put it on your Site (Insert>More Gadgets>add gadget by url and specify the url where you have stored it)

Searches this site and other Google Sites help sites


<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Hello World!" />
  <Content type="html">
    <![CDATA[
      <div id="cse-search-form" style="width: 100%;">Loading</div>
<script src="//www.google.co.uk/jsapi" type="text/javascript"></script>
<script type="text/javascript">
  google.load('search', '1', {language : 'en', style : google.loader.themes.MINIMALIST});
  google.setOnLoadCallback(function(){
    var customSearchControl = new google.search.CustomSearchControl('010428851484230611414:dbm31yqzwea');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    var options = new google.search.DrawOptions();
    options.enableSearchboxOnly("http://www.google.co.uk/cse?cx=010428851484230611414:dbm31yqzwea", null, true);
    customSearchControl.draw('cse-search-form', options);
  }, true);
</script> 
]]></Content>
</Module>


Simple Gadget Creation and hosting

  1. Create a new XML file (can be a text file with file extension of .xml) in any text editor such as Notepad - save with UTF-8 encoding.
  2. Copy and paste the following base code for the gadget into the text editor:

    <?xmlversion="1.0" encoding="UTF-8"?>
    <Module>
    <ModulePrefs title="Custom Gadget" />
    <Content type="html"><![CDATA[
    Insert the custom content, script, JavaScript, CSS ad code, tracking code or other code here...
    ]]></Content>
    </Module>

  3. Replace the “Insert the custom content, script, JavaScript, CSS ad code, tracking code or other code here…” with the actual code to display by the gadget on the web pages hosted on Google Sites.
  4. Replace the “Custom Gadget” with your preferred title for the gadget.
  5. Save the file with any file name with .xml extension to make it a gadget. For example, gadget.xml.
  6. Upload the .xml gadget to an online website.
  7. To host at Google Sites, create a page or edit an existing page, then add the file as an attachment.
  8. Copy the url of the gadget. If hosted on a Google site, right click on the download link and 'copy link address'
  9. Insert>More Gadgets>add gadget by url and specify the url from step 8.

ċ
gcse.xml
(1k)
Philip Ridout,
10 Nov 2012, 07:57
Comments