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(); | |
}); |
Thanks.
A little improvement for my requirements, I want to be able to control which hyperlink get an target attribute.
Markdown document example snippet:
[read this resource.][topic-name-resources-id1]
[topic-name-resources-id1]: https://google.de "#ext: read this resource."
open-in-blank.js:
function addBlankTargetForLinks () {
$('a[title^="#ext"]').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
tks share