How to do internal searches on the site by google via javascript

Asked

Viewed 403 times

0

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

Code js:

<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 to search only within my site?

1 answer

0

  • I put that where in the code? because I tried it here and it didn’t work no, it continues the same way.

  • @Arthurmoraes where your HTML is populated the search data?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.