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.
<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.

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.


Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...