Last active
January 2, 2016 17:38
-
-
Save rjv/8337705 to your computer and use it in GitHub Desktop.
Open external links in a new window
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
// create custom selector for external links | |
$.expr[':'].external = function(obj){ | |
var $this = $(obj); | |
return !$this.is('[href^="mailto:"]') && !$this.is('[href^="javascript:"]') && (obj.hostname != location.hostname) && ($this.data('target') != "top"); | |
}; | |
// DOM is ready | |
$(function(){ | |
// apply target="_blank" to each external link on the page | |
$("a[href]:external").attr("target", "_blank"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment