Created
January 16, 2014 18:39
-
-
Save kmgdevelopment/8460749 to your computer and use it in GitHub Desktop.
Exclude Excepted Links from Open-in-New-Window Script
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
var exceptedLinks = [ | |
'.webinars .banner .share a', | |
'.someotherlink' | |
] | |
$('a').each(function() { | |
var link = $(this); | |
excepted = false; | |
// check if the link is in the exceptedLinks array | |
$.each(exceptedLinks, function(index, value){ | |
if( link.is(value) ) { | |
excepted = true; | |
return false; | |
} | |
}); | |
if(!excepted) { | |
// get this site's URL | |
var siteUrl = new RegExp('/' + window.location.host + '/'); | |
// check if the link is an actual web link | |
if( this.href.match(/^http/) ){ | |
// check if the link contains this site's URL | |
if( !siteUrl.test(this.href) ) { | |
$(this).click(function(event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
window.open(this.href, '_blank'); | |
}); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment