Google Custom Search Engine (CSE) is a service that allows you to create a search engine for your website, using the power of Google's search technology. You can customize the look and feel of the search results, as well as specify which websites should be included or excluded from the search.
To use Google CSE on your website, you will need to create a CSE account and obtain a search engine ID. Once you have the search engine ID, you can use the following code to embed a search box on your website:
<!-- Replace YOUR_SEARCH_ENGINE_ID with your actual search engine ID --> <div id="cse-search-form">Loading</div> <script src="https://cse.google.com/cse.js?cx=YOUR_SEARCH_ENGINE_ID"></script> <script> var searchForm = document.getElementById('cse-search-form'); var searchBox = new google.search.SearchForm(searchForm); </script>
This will create a search box on your page that users can use to search the websites you have included in your CSE. The search results will be displayed in an iframe on your website.
You can also customize the appearance and behavior of the search results by using the Google CSE API. The API allows you to specify the layout and style of the search results, as well as programmatically interact with the search results and handle search events.
Here is an example of how you can use the Google CSE API to customize the search results:
<div id="cse-search-results"></div> <script> function onLoad() { var searchForm = new google.search.SearchForm(document.getElementById('cse-search-form')); var searchControl = new google.search.SearchControl(); searchControl.addSearcher(new google.search.WebSearch()); searchControl.addSearcher(new google.search.VideoSearch()); searchControl.draw(document.getElementById('cse-search-results')); } google.setOnLoadCallback(onLoad); </script>
This code will create a search box and search results on your page, and include both web and video search results in the search results. You can customize the layout and style of the search results by modifying the CSS of the search results element.
I hope this helps! Let me know if you have any questions.
Comments
Post a Comment