The script works in both blogger and wordpress.
HOW TO OPEN ALL YOUR EXTERNAL LINKS IN A NEW TAB
1. Navigate to Blogger Dashboard > Template2. Now choose Edit HTML. (Note: Always do a backup while editing your template)
3. Search for </head> and just above it paste the below code.
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script> <script type='text/javascript'>4. Save the template.
$(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 1: Do not add the bolded code if your blog template already have jQuery library linked in.
NOTE 2: If you change == -1) in the code highlighted in yellow to == 1) then all your internal links will start opening in a new tab.
That’s it. Just check your blog and click on any external link to see it working. Hope this was helpful.
Credits: This script was originally shared by Mohammad Mustafa Ahmedzai of MBT. You should thank him. Peace:)
Comments
Post a Comment