Skip to main content

Blogger Tweak - Open external links in new tab automatically

So, once upon a time, a really long while ago, I tried to customise and recreate a Blogger template which is not available anymore, but there's one thing I remember about it. I had a jQuery code written to make all the external links open in new tab. I also thought, it's about time I revive that idea and write a more intact code and here we go. 

So, there are two things to do. 

  1. Add Javascript code that detects external links and opens them in new tab.
  2. Add a CSS code to let users know that a particular link is going to be opened in new tab.

Adding a javascript code

Please follow the instructions below,
  1. Go to dashboard
  2. Navigate to Themes > click the down arrow near "Customize" and then click on Edit HTML.

  3. Now scroll to the very end and paste the following code just before </body> tag.
    <script type='text/javascript'>
          if( === &quot;A&quot;){
          if(!;krishnainfotron&quot;) &amp;&amp;;http&quot;)){
  4. The code above should look like,

  5. Here, please replace krishnainfotron with the keyword that your blogspot and custom domain have in common. For example, my blogspot address is and my custom domain address is Since both of them have krishnainfotron in common, I have added that as keyword so that both blogspot and custom domain links in my blog will be detected as own link and open others in a new tab. 
  6. Once done, please click on the floppy icon at the top right which indicates Save.

Now, your blog will open all external links in new tab. Please test it out. Let's move on to the second part of the article,

Adding a CSS code

This CSS code is to show an indication that it's an external link and will open link in new tab. Please follow the instructions below,
  1. Go to > Themes > Customize
  2. In the left, click on Advanced > In the appearing dropdown, choose "Add CSS"

  3. In the appearing text box, please paste the following code,
    a[href]:not([href*="krishnainfotron"]):not([href*="bp.blogspot"]):not([href*=""]):not([href*="googleusercontent"]):not([href=""]):not([href^="/"]):not([href*="javascript"])::after {
    content: "";
    background-image: url('');
    background-size: 15px;
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-left: 5px;
    margin-right: 5px;
    bottom: 0px;
  4. Here, again please change your blog's keyword. The rest of the restrictions are to ignore image links, blogger original links etc., Although they will be opening in new tab, we don't indicate them for neatness.
  5. Click the floppy icon in the bottom right that represents save.

  6. Now you can see external links in my blog having a "Open in new tab" icon nearby as shown below,

Being all that done, it should be sufficient for opening external links in new tab at lowest code cost. Happy blogging everyone.

Please note that the image is taken from with creative commons licence and it is best to give attribution for using it like I have given in my right side bar using a HTML/Javascript gadget,
(P.S - If at all do you face any problems like some links that are not supposed to open in new tab opens etc., please comment on this article so that I can check and rectify it)

See related posts:


  1. helpful but... it's opening all the links in new tab now. I mean even the links which leads to a blogpost of the same blog. It's a problem. please reply me how can I solve it. Thank you

    1. It might be too late that you figured out the issue but am happy to help if you could create new thread at the blogger help forum ->


Post a Comment

People also read,

How to secure your Google account and Blogger blog?

As a part of contributions to NCSAM, I am writing this article down on what all should we be aware of with respect to Google's security aspect and how to make sure your blog stays yours forever. What is NCSAM? It's National Cyber Security Awareness Month which is observed during the month of October every year in America. However, we all know cyber security is a world topic and is not limited to just the USA. So let me give some tips with respect to keeping the Google account safe and Blogger blogs safe from hackers. As I secure my account, I hope you people catch up too. In this blog post, I am going to tell about the following, Securing your Google account. Securing your Blogger blog. Securing your Google account Since Blogger is also part of your Google account, let's first see what all we need to do to keep our Google account safe. Don't share your password to anyone. Keep changing your password every 60 - 90 days. Make sure your password is str

Blogger & Twitter card previews

 So, there was a report in Blogger Help Community which is what made me write this down.  This is in correlation with Blogger & Facebook OG Object debugger . The report was that Blogger blogs doesn't show preview in Twitter card validator . So, I went ahead and tried previewing one of my blog posts and I got the following, Therefore, I tweeted the same link which is here and it didn't show any preview.  Hence, I concluded not just the validator, the whole twitter stopped scraping my open graph information. Therefore, I made a small research and added a tag in my template. Please follow instructions below, Go to  > Themes Click on the three dot menu near "My Themes" and choose Edit HTML In the appearing page, press Ctrl + F and find the below code, <b:include data='blog' name='all-head-content'/> Right after that code, paste the following code, <meta name="twitter:card" content="summ