var searchReturned = false; try { // #1 google.load('search', '1', {language : 'en'}); google.setOnLoadCallback(function() { var customSearchControl = new google.search.CustomSearchControl('XXXXXXXXXX'); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); customSearchControl.setNoResultsString("Your search didn't return any results."); customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) { // #2 searcher.setQueryAddition("inurl:<<searchPath>>"); searcher.setRestriction(google.search.Search.RESTRICT_EXTENDED_ARGS,{ "filter" : "0" }); }); customSearchControl.setSearchCompleteCallback(this, function(control, searcher){ $("#search_preload, .gs-no-results-result").hide(); $("#search_postload").show(); // #3 if($('.gs-spelling').length) { $('.gs-spelling a').html($('.gs-spelling a').html().replace(/inurl:.+/g,"")); } // #4 try { numResults=searcher.cursor.estimatedResultCount; $("#searchResultNum").text(numResults); var cpi = searcher.cursor.currentPageIndex; if (cpi < searcher.cursor.pages.length - 1) { $('#cse .gsc-cursor').append('<div class="gsc-cursor-page">Next</div>').click(function() { searcher.gotoPage(cpi + 1); }); } if (cpi > 0) { $($('#cse .gsc-cursor').prepend('<div class="gsc-cursor-page">Previous</div>').children()[0]).click(function() { searcher.gotoPage(cpi - 1); }); } } catch(e){} window.scrollTo(0,0); searchReturned=true; }); var options = new google.search.DrawOptions(); options.setInput($('#search-box-input')); options.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); customSearchControl.draw('cse', options); // #5 customSearchControl.execute('<<query>>'); }, true); } catch(err) {} // #6 setTimeout(function(){ if(!searchReturned && $('#cse').length == 0) $("#search_preload").html("<h2 style='color:red;'>There was an error performing your search, please try again later.</h2>"); }, 10000);
If you're using the Custom Search Element, find this line in your code:
customSearchControl.draw('cse', options);
Above that line, add this code:
customSearchControl.setSearchStartingCallback(this,
function(control, searcher, query) {
searcher.setQueryAddition('-inurl:https');
});
make sure you add this to the result section of your page not the form box.