Automatically Open all External Links in a New Tab!

advertise here







Open all the external links in new tab or new window in blogger. Rather then adding target="_blank"  inside all the outgoing links just add below code and all the links going out from your blog will be open in the new window or new tab. Follow the below steps.

  1. Go to blogger dashboard
  2. Template
  3. Click on Edit Template
  4. Search for </head> tag in the code. and paste below code above it.

<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>
    6. Save the template. 
Don't forget to share it with friends.

Click to comment