Skip to content

Instantly share code, notes, and snippets.

@kmgdevelopment
Created January 16, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmgdevelopment/8460749 to your computer and use it in GitHub Desktop.
Save kmgdevelopment/8460749 to your computer and use it in GitHub Desktop.
Exclude Excepted Links from Open-in-New-Window Script
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