Wednesday, October 7, 2015

How to Open All External Links in New Tab in Blogger

To prevent your blog readers from leaving your blog without reading any or only one post, you must think to open links from your blog in new tab. It also helps in increasing your overall page views and reducing bounce rate. Blog bounce rate is one of the important factors in blogging and is simply defined as number of readers leaving your blog without reading any or only one post. It means more the bounce rate lesser the engagement. When we consider reducing our bounce rate, the first thing our mind suggest is opening the links in new tab and its importance increases when it comes to external links.
This can be done manually for each link you want to open in new tab by by adding target=”_blank” inside hyperlink or in blogger editor when you are putting a link by checking the property Checkbox “Open this link in a new window”  as shown in below snapshot.
But this way may be a tough task if you have a enormous number of links to do this. So here I am giving you a simple jQuery script to open all external links in new tab.

Steps to Open all External Links in New Tab :

  • Go to your blogger dashboard
  • Select your blog >> Template
  • Backup your template before editing
  • Click on “Edit HTML”
  • Find </head> tag in HTML
  • Add the following piece of code just above the </head> tag
  • Save your Template, you are all done !! 
Note : Please don’t add the red code if you already have jQuery library source code installed on your blog.
 <script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script> <script type='text/javascript'> $(document).ready(function() { $("a[href^='http://']").each( function(){ if(this.href.indexOf(location.hostname) == -1) { $(this).attr('target', '_blank'); } } ); $("a[href^='https://']").each( function(){ if(this.href.indexOf(location.hostname) == -1) { $(this).attr('target', '_blank'); } } ); }); </script>

Affected Links By Above jQuery Script:

Above jQuery script will check all hyperlinks inside your blog pages and will add the target=”_blank”  attribute to links which are external. It wont  put any effect to internal links of the blog. The script will only detect external hostnames and the moment it finds one, it will insert into the html a target attribute that tells the browser to open the link in a new window.
HostGator Web Hosting

0 comments:

Post a Comment