Thursday, September 22, 2011

Blogger Links Open in New Tab (HTML)

It has been an old time heresy for blogger users, because by default blogger blogs' external links opens in the same tab or window where the blog's page exists. So, I reckon this heresy will not exist for further times as I am here to help your blog's link to open in a new tab.

Well, you may guess that I will tell you to edit the HTML of your every anchor texts in your blog post, but trust me, this is not going to happen. All I will tell you to do is just a task of one minute. So to assign your external links open in a new tab (not new window) using JQUERY, follow the steps listed below.

Procedure:



  • Log-in to your blogger account; go to Design --> Edit HTML, Or for new blogger interface, go to Template --> Edit HTML.
  • Now, press Ctrl+F and find </head>.
  • Just before </head>, paste the following code. 

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'/>
<script type='text/javascript'>

$(document).ready(function () {

// ---- External Links ----------------------------------------------------------------------------------------------------

$(&quot;a[href*=&#39;http://&#39;]:not([href*=&#39;&quot;+location.hostname+&quot;&#39;]),[href*=&#39;https://&#39;]:not([href*=&#39;&quot;+location.hostname+&quot;&#39;])&quot;).attr(&quot;target&quot;,&quot;_blank&quot;).attr(&quot;title&quot;,&quot;Opens new window&quot;).addClass(&quot;external&quot;);

});
</script>


  • Now click on Save Template
You're all done. Just click on any external links in your blogger posts, and it'll open in a new tab. :) However, this HTML code to open links (external) links in a new tab are pasted here from my template directly, so I reckon there's error, but if you find any kind of error just leave a comment because I love comments. :x