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

Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

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.
 
comments powered by Disqus
Other posts you may like...