Forked from wpscholar/jquery.external-links-new-window.js
Last active
August 9, 2016 17:46
-
-
Save bompus/847f81be606118d13e6d8bd7795ac2e8 to your computer and use it in GitHub Desktop.
Open all 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
/** | |
* Open all external links in a new window | |
*/ | |
require(["jquery"], function($) { | |
var isInternalLink = new RegExp('/' + window.location.host + '/'); | |
$(document).on("click", "a", function() { | |
var t = $(this); | |
if (!isInternalLink.test(t.attr("href"))) { | |
t.attr('target', '_blank'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment