
First methode
1. Go to Layout>Edit HTML, and look for this line:
</head>
2. Paste the code below, just before that line
<base target="_blank" />
3. It looks like this:
</head>
<base target="_blank" />
All your links by now should open in new windows.
Open all external links in a new tab
Note: This method works for both blogger and wordpress blogs, irrespective of platforms.
- 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/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: Don't 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!
Check your blog and click some external links to see it working just fine.
How it works? (Optional know-how)
Normally all bloggers blogs have hostnames starting with http:// without the http:// secure protocol. Therefore it's added the second instance so that the script may work even for wordpress self hosted blogs.
The yellow highlighted part is where the script scans values inside href attributes and if the value is equal to a negative one (== -1), then this indicates that the hostname is an external domain.
Note: If you equate the href value to a positive one (==1) inside the conditional statement, then all your internal links will start opening in new windows!
Once the condition is met, the script then inserts a target="_blank" attribute inside the hyperlink tag. That simple!
Hope this script proves helpful for most of you. It is extremely SEO friendly and works fine with all major browsers be it IE, webkit browsers or Mozilla.