Open all external links in a new tab

O

Open all external links in a new tab
Follow these easy steps to add this cool dynamic way of updating all external links.
Note: This method works for both blogger and wordpress blogs, irrespective of platforms.

  1. Go to Blogger > Template
  2. Backup your template
  3. Click “Edit HTML”
  4. Just above </head> paste the following script: 

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

PS: Please do not add the red code if you already have jQuery library source code installed on your blog.
     5. Save your template and you are all done!

About the author

domdom rung

1 comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Categories

Recent Posts

Recent Comments

Archives