Setting Site Restriction to Google Ajax Search API

You can set site restriction to Search Engine created through Google Ajax Search API. setSiteRestriction() is the method using which you can restrict your search to specific site. Method setSiteRestriction('site-address'') can only restrict your search to one site only. If you want to restrict your search result to more than one sites then this way will not work!

You cannot do like this:


For restricting your search to multiple Sites, you need to use Google Custom Search Engine with Google Ajax Search API. Create Custom Search Engine with sites you want to include and get the Unique ID of that Search Engine.

<script src="" type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
google.load('search', '1');
function OnLoad() {
// Create a search control
var searchControl = new;
// Add in a full set of searchers
var websearch   = new;
// Method One. For one website only
// websearch.setSiteRestriction("");
// Method Two - For set of sites. Supply Custom Search Unique ID
// Attach the result to 'mysearch''
// execute an inital search

<div id="mysearch">Loading</div>

Remember you need to get the Ajax Search API key for your website. Google Ajax Search API is mentioned at key=ajaxsearchAPI. This is not a valid search API. Likewise Custom Search Unique Id is also not a valid Id.!

  • # 1 - by Dan

    Thanks for this info…….

  • # 2 - by Dan

    Thanks for this info…….

Comments are open for an year period. Please, write here on Facebook page.