The other day I published about the benefits of using Google Custom Search Engine (CSE). If you haven’t gone through these benefits –you should. CSE has a lot of advantages over using your own website’s search.
Google CSE is a free service. Just open a Google account, go to the CSE page, create a CSE and select its look and feel and features. Get the code, paste it in your website and you’re done! It is as simple as that. However, if you want to fine-tune your search engine –you may need to do a bit of research. One of the common question that people have is “how do I change the link target of search results thrown up by Google?”
The default link target of Google CSE is “_blank” but many webmasters want links to open in the same window (or, although rarely, in an iframe or frameset). Here we present the solution to this problem.
The code for CSE you get from Google has three parts:
- A JavaScript code
- Markup for place where search box is to be rendered
- Markup for place where search results are to be shown
To change the target of links, you would need to make a small change in the last item. You get the following markup from Google:
<gcse:searchresults></gcse:searchresults>
And you need to add the linkTarget attribute to this markup. For example:
<gcse:searchresults linkTarget=”_parent”></gcse:searchresults>
Value of this attribute can be anything that is acceptable as a link target (i.e. top, blank, parent, self or a frame’s name). The above example will open the search result links in the same window.
Which linktarget is more suitable for you all depends on your need and design of you website or blog. Thankfully Google has provided us the facility to decide linktarget on our own.
I hope this small tip saved you some time and solved your problem. Please let me know if you have any questions about this topic. Thank you for using TechWelkin.
Where have I to place the gcse tag? in the script?
Thank you. I got benefited from this information.
how to redirect links in HTML frame? Like if I click on link its opening in new tab. I want to open it in my HTML iframe so I can do what ever I want to do with it. thank you
Check out CSE options. If it allows you to change the target of links -then it’s possible. Otherwise, you can’t change the link target because these search results are created by Google and we should not tamper with them.