Click Here to Earn 10$

Make links to open in a new window

If you have lots of external links and you want your readers to external links in new window and not willing to manually do it for each link by adding target="_blank" then follow the below steps:



Go to Blogger > Template

Backup your template

Click "Edit HTML"

Just above </head> paste the following script:


<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'/> 

<script>
//<![CDATA[
$(document).ready(function() {
  $("a[href^='http://']").each(
    function(){
     if(this.href.indexOf(location.hostname) == -1) {
        $(this).attr('target', '_blank');
      }
    }
  );
});
//]]>
</script>

Note: Please do not add jQuery library(Code in blue) If you have already added  to your template.
Hope this script proves helpful for most of you. If any Problem persist please comment below.

0 comments:

Post a Comment