Header Ads

Open all external links in new tab in Blogger and Wordpress blogs

You can't automatically open all the external links in a new window/tab in Blogger or Wordpress blogs unless you add "target=_blank" attribute to hyperlinks.But I have found a piece of code that can add inside your templates which will open all external links in new tab or window.



  • Steps to add the "target=_blank" java script.
  1. Go to Blogger > Template
  2. Backup your template
  3. Click "Edit HTML" 
  4. Just above </head> tag paste the following script:
  5. Save your template
    <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:Do not add the yellow code if you already have j query library source code inside your template.This code is SEO friendly it won't harm any way.Work with all browsers.If you are having problems just ask by comments.
www,techgossip.ml. Powered by Blogger.