How to Open Google Custom Search Links in Same Window

By Posted 2012 Updated   BloggingGoogleTutorials

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.

Google custom search

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>


6 comments on “How to Open Google Custom Search Links in Same Window

  1. Curtis says:

    It’s s good idea — and something I’ve been looking to do, but we’re not using the Version 1 code (and there are many reasons it’s not a good idea to use the old code). Would love to know how to open the search results in the same window in Version 2. By the way, QOT is my new favorite blog – thanks.

    • Dave says:

      In version 2, add linktarget=”_parent” in the gcse:searchresults-only line on the results page.

      Example:

  2. James Wilcox says:

    Had this question today and figured out how to do it using the new code:

    Google’s Documentation has all the options you can use:
    https://developers.google.com/custom-search/docs/element

  3. James says:

    Great simple solution to a pretty irritating problem. Thanks for sharing!

  4. Ali says:

    I have used the linktarget=”_parent” on the search results page and it works a charm. I also had a look at the Google Custom search API and it only says what the default is. This helped. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *




Next Article »
css.php