How can you make Google custom search results open links in same window? Many Webmasters use the excellent free Google custom search to power their site search, but the default code opens the search results in new window. It would be preferable if the links opened in the same window for better user experience.
I wondered why Google search results open in new windows. For example, after displaying the search results if the visitor wants to view your three articles, he clicks on all the three links and all open in three different windows. That is good in one way, but what if he wants to just review one result, and opening result in a new window would spoil the user experience.
Long time visitors would know that we use Google custom search for several years now. Earlier we used the Google AdSense for search to generate income from search results, but now we prefer the Google custom search, which recently also became ad free, and also show images results. You can search any terms from the search box on the right sidebar, and test yourself how well the Google search results display here.
Google Custom Search: Open Links in same window
Google custom search recently released the version 2 code, which is a more compact code. The version 1 code was more detailed, and we will edit this code to open search results in the same window.
We display our custom search box on our site, which is super fast loading. The results are displayed on a separate search results page which contains the Google custom search code and loads all the scripts necessary to display search results.
It is a long code which you must have cut pasted where you want the search results to display. Find the following line of code first
customSearchControl.setResultSetSize (google.search.Search.FILTERED_CSE_RESULTSET);
and add this new line of code beneath it which forces the search result links to open in new window.
customSearchControl.setLinkTarget (google.search.Search.LINK_TARGET_TOP);
Save the search file, refresh the window and now your search results will open clicked links in the same window, and will keep the users happier. I hope you like this Google site search tip.
Update: In version 2 code you can choose to add this code where the custom search results appear.
<gcse:searchresults linktarget="_parent"></gcse:searchresults>