Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I use Google Custom Search on a number of my websites and it works really well. Unfortunately for some reason Google decided that links on the rendered search results would open in a new window/tab by default i.e. they have their target set to _blank. This is not desirable in most cases but luckily there are two simple ways to fix this and force links to open in the same window/tab as the search results.

The first way is modifying your CSE code, specifically the gcse element. Add a linktarget attribute and set it to "_parent". This will force any links from search results to open in the same window/tab as the search results themselves.
 HTML
<gcse:searchresults-only linktarget="_parent"></gcse:searchresults-only>


The second and perhaps easier option is to make the change right in the CSE console. In the Search features section under the Advanced tab enter _parent to the Link Target option, then click Save.
googlecse.png


That's all there is to it! Of course there are other configuration options and parameters and these are documented over at the Custom Search Element Control API page.



-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.