Created
January 13, 2013 11:33
-
-
Save azone/4523641 to your computer and use it in GitHub Desktop.
Open Octopress external link in new tab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addBlankTargetForLinks () { | |
$('a[href^="http"]').each(function(){ | |
$(this).attr('target', '_blank'); | |
}); | |
} | |
$(document).bind('DOMNodeInserted', function(event) { | |
addBlankTargetForLinks(); | |
}); |
I did a little change. Only add _blank to those links with no target attribute.
What's more, you should note that jquery is required to make the code running.
$(document).bind('DOMNodeInserted', function(event) {
$('a[href^="http"]').each(
function(){
if (!$(this).attr('target')) {
$(this).attr('target', '_blank')
}
}
);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.
A little improvement for my requirements, I want to be able to control which hyperlink get an target attribute.
Markdown document example snippet:
open-in-blank.js: