public
Last active — forked from kaelig/application.js

JQUERY: Open external links and PDFs in a new window or tab

  • Download Gist
application.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$(document).ready(function() {
// Open external links in a new window or tab
$(document).on('click', 'a[rel$="external"]', function() {
$(this).attr('target', "_blank");
});
$(document).on('click', 'a[href$=".pdf"]', function() {
$(this).attr('target', "_blank");
});
// Open all urls that don't belong to our domain in a new window or tab
$(document).on('click', "a[href^='http:']:not([href*='" + window.location.host + "'])", function() {
$(this).attr("target", "_blank");
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.