Mobile Number Tracker
Trace Mobile Number Earn Money Online
© TechWelkin.com

Custom Search Engine (CSE): Change Link Target to Parent or Blank

Samyak Lalit | October 13, 2013 (Last update: April 24, 2021)

Samyak Lalit is an Indian author and disability rights activist. He is the principal author and founder of projects like TechWelkin, WeCapable, Viklangta, Kavita Kosh among many others.

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.

How to Change Link Target of CSE Search Results

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.

© TechWelkin.com

4 responses to “Custom Search Engine (CSE): Change Link Target to Parent or Blank”

  1. Wolfgang says:

    Where have I to place the gcse tag? in the script?

  2. Erkan says:

    Thank you. I got benefited from this information.

  3. pranav says:

    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

    • Lalit Kumar says:

      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.

Leave a Reply

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