Created
July 26, 2012 12:35
-
-
Save ms-studio/3181778 to your computer and use it in GitHub Desktop.
jQuery outgoing-links-in-new-window function
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
$(document).ready(function() { // The @ syntax is no longer supported in JQuery 1.3+. | |
$("a[href^=http]").each( | |
function(){ | |
if(this.href.indexOf(location.hostname) == -1) { | |
$(this).attr('target', '_blank'); | |
} | |
} | |
) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: you may want to restrict it to the main content of your pages, such as:
$("#main a[href^=http]").each(...)