Hey there, I recently wrote some Jquery to make all links external to a site have the target=”_blank” using the following code:
$('div#outer-wrapper a').each(function(){
var hrefpull = $(this).attr("href");
if (typeof hrefpull != 'undefined'){
if (hrefpull.charAt(0) == '/' || hrefpull.charAt(0) == '#' || hrefpull.charAt(0) == ''){
// Skips over anything with a / # or nothing!
}else{
var checker = hrefpull.split("/");
if (checker[2] != $baseUrl){
$(this).attr('target', '_blank')
}
}
}
});
Now it adds target=”_blank” no problem… however… when I click on a link, it loads the link in both a new window and the current window. What is causing this, and how do I fix this?
Instead of adding target=”_blank” I would recommend that you open the link in a new window from javascript. Something like this: