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.
- Go to Blogger > Template
- Backup your template
- Click "Edit HTML"
- Just above </head> tag paste the following script:
- 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>
Post a Comment