javascript google search function

0

I created a javascript function that does searches within my site with the google search API, but I would like the word I type to appear only something linked to my site, it is currently bringing results from google.

js code:

<script>
    (function() {
        var cx = 'minhachave';
        var gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:')
        '//cse.google.com/cse.js?cx=' + cx
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
    })();
</script>

How do I search only within my site?

    
asked by anonymous 25.09.2017 / 17:33

1 answer

0

You can use element gcse:search with the as_sitesearch attribute, for example:

 <gcse:search as_sitesearch="www.site_do_arthur.com"></gcse:search>

Documentation: link

    
25.09.2017 / 17:48