Sunday, 19 January 2014

Filled Under:
,

Automatically Open all External Links in a New Window in Blogger!

SOCIALIZE IT →
 In this post I'll tell you how to add automatically target blank to every external link in your all posts. Some time blogger forget to add target blank tag to the external link and when the visitor click on the external link, visitor will leave your blog because you have not set the target blank on that link. I give you a simple jQuery code which automatically set all target blank tag to all external link. By adding the code in your blog template all the external links will open in new tab and your visitor remain on your blog. It wont effect on your internal linking.

Open all external links in a new tab :

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. :)
Check your blog external links that it working fine on your blog.

Final Words : 
I hope you'll like this tutorial and share with your friends. If you need any help comment below.
Get Free Updates in your Inbox
Follow us on:
facebook twitter gplus pinterest rss





Comment With:
OR
The Choice is Yours!

4 comments: