Return to Snippet

Revision: 27826
at June 24, 2010 20:11 by marzsman


Initial Code
<script src="http://www.google.com/jsapi?key={google_search_api_key}" type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
//<![CDATA[
var query = '<?php if(isset($_GET['q'])) echo $_GET['q']; ?>';
var noResultsStr = "{no_results_str}"
google.load("search", "1");
// Call this function when the page has been loaded
function initialize() {
    // Dynamically load CSS to override defaults
    var options = new google.search.SearcherOptions();
    options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
    
    var siteSearch = new google.search.WebSearch();
    //siteSearch.setUserDefinedLabel("{tab_lbl}");
    siteSearch.setUserDefinedClassSuffix("siteSearch");
    siteSearch.setSiteRestriction("{google_cse}");
    
    var searchControl = new google.search.SearchControl();
    searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
    searchControl.addSearcher(siteSearch, options);
    searchControl.setNoResultsString(noResultsStr)
    
    // create a drawOptions object
    var drawOptions = new google.search.DrawOptions();
    // tell the searcher what input field to use
    drawOptions.setInput(document.getElementById("{search_input_id}"));
    // tell the searcher to draw itself in tabbed mode
    drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
    searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
    
    searchControl.execute(query);
}
google.setOnLoadCallback(initialize);

//]]>
</script>

Initial URL

                                

Initial Description

                                

Initial Title
Google Ajax search

Initial Tags
ajax, search, google

Initial Language
JavaScript