Open blogger blogspot or webpage links in new window

Open all links on the web page in new window: Default HTML supports this.

Add following code after the <head> but before </head> tag of your HTML:  

<base target='_blank' />


If I make all links needs to be opened in new window then home link, navigation links, search everything will opened in new window and it will frustrate user that whatever you click on the link it will open in new window. Dozens of windows in user system if you click 10-12 links. Not a good idea.
Example:

<head>
<base target='_blank' />

The target is open in the new window just external links from your blog, Here is a vanilla javascript solution, that you want to paste into your template just before the end of the body (if you're old-style template), or paste into a javascript widget:

Replace XXXXXX with the appropriate URL prefix.



<!-- code for turning all non-blog links to new page links -->
<script type="text/javascript" language="javascript">
   var arr = document.getElementsByTagName("a");  //get all links in the page
   for(var i = 0; i < arr.length; i  )
   {
      if(arr[i].href.indexOf("XXXXXX.blogspot") < 0 //not links that are 'inside' blog
         && arr[i].href.indexOf("javascript:") < 0) //not javascript links
         arr[i].target = "_blank";
   } 

Or

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
jQuery('a').each(function() {
    // Let's make external links open in a new window.
    var href = jQuery(this).attr('href');
   
    if (typeof href != 'undefined' && href != "" && (href.indexOf('http://') != -1 || href.indexOf('https://') != -1) && href.indexOf(window.location.hostname) == -1) {
        jQuery(this).attr("target", "_blank");
    }
});
//]]>
</script>
Previous Post Next Post