/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<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>