Friday, 14 March 2014

How to Automatically Open All External Links in New Tab/Window ?

Today I'll explain how you can automatically targeted blank to every external links attached with your blog posts.Most of the times, bloggers forget to add target blank tag towards the external link so when the visitor click the external url, visitor may leave your blog because you might have not set the mark blank about that url. I am going to tell you with a simple jQuery code which immediately set all target blank tags to all external links. By adding this code in your blog template each of the external back links will be open in a new tab whilst your visitor stick to your web site. It wont affect on your inner linking. So lets see how to add this script to your blogspot blog.




How to Add to Blogger?

Follow the  easy step to add target attribute to your all external links.
Go to your blogger dashboard.
Select your blog >> Template >> Edit HTML 
and Add the following piece of code just above the </head> code


    <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>

Note : Don't add the red code if you already have jQuery library code installed in your blog.
Save your template and you have all done. :)


In the Last:

This is an small and easy task to add this script and reduce your blog bounce rate. Now It's your turn to share this post and write your feedbacks in comments till then Peace, Blessings and Happy Linking.

No comments:

Post a Comment