From 86b8a6aa1b2ea020fc90dacdb3b1f99b4b6e954f Mon Sep 17 00:00:00 2001 From: Ivan Fonseca Date: Sun, 29 Jul 2018 19:10:49 -0400 Subject: [PATCH] Use link host to find external links --- .../js/behaviors/external-links-new-tabs.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tildes/static/js/behaviors/external-links-new-tabs.js b/tildes/static/js/behaviors/external-links-new-tabs.js index d89180f..20b90f3 100644 --- a/tildes/static/js/behaviors/external-links-new-tabs.js +++ b/tildes/static/js/behaviors/external-links-new-tabs.js @@ -1,17 +1,8 @@ $.onmount('[data-js-external-links-new-tabs]', function() { - /* Open external links in topic, comment, and message text in - * new tabs. - * - * The regex matches links starting with "/" or "tildes.net", which are - * "internal" links to Tildes pages (posts, topics, users, etc). All - * other links are considered "external" and open in a new tab. - */ - let re = /^((?!\/).)$|^https?:\/\/((?!tildes\.net).).*$/gm; - // Loop through links + // Open external links in topic, comment, and message text in new tabs $(this).find('a').each(function() { - // Check if href is external - if (re.exec(this.href) !== null) { - $(this).attr('target', '_blank'); + if (this.host !== window.location.host) { + $(this).attr('target', '_blank'); } }); });