title: How can I specify as_sitesearch in v2 of Google Site Search / Custom Search?
body: <p>I have a Google Custom Search (that will be a Site Search in the future) and I'd like to use the snippet that Google provides:</p>
  
  <pre><code>&lt;script&gt;
    (function() {
      var cx = '...';
      var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
          '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
    })();
  &lt;/script&gt;
  
  &lt;gcse:search&gt;&lt;/gcse:search&gt;
  </code></pre>
  
  <p>I need to restrict it to certain urls. When using the xml api, you can use the parameter as_sitesearch to specify this filter.. is there a way to do this with the code above?</p>
  
  <p>with this I can now access the google.search.cse object before the search is loaded.. but I still don't know parameter:</p>
  
  
  
  <pre><code>&lt;script&gt;
  
  
  var myCallback = function() {
    if (document.readyState == 'complete') {
      // Document is ready when CSE element is initialized.
      // Render an element with both search box and search results in div with id 'test'.
      google.search.cse.element.render(
          {
            div: "test",
            tag: 'search'
           });
    } else {
      // Document is not ready yet, when CSE element is initialized.
      google.setOnLoadCallback(function() {
         // Render an element with both search box and search results in div with id 'test'.
          google.search.cse.element.render(
              {
                div: "test",
                tag: 'search'
              });
      }, true);
    }
  };
  
  // Insert it before the CSE code snippet so that cse.js can take the script
  // parameters, like parsetags, callbacks.
  window.__gcse = {
    parsetags: 'explicit',
    callback: myCallback
  };
  
  
    (function() {
  
      var cx = '007407192365638902354:eyxoavi7oa0';
      var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
          '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
    })();
  &lt;/script&gt;
  
  
  
  &lt;style&gt;
  .gsc-control-cse * {
  box-sizing:content-box;
  }
  &lt;/style&gt;
  </code></pre>