From a909ca62e6e79384468e4a48119b4e437135539e Mon Sep 17 00:00:00 2001 From: Jason Yavorska Date: Mon, 3 May 2021 17:36:03 +0200 Subject: [PATCH 1/2] Open external content in new tab --- app/packs/entrypoints/application.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/packs/entrypoints/application.js b/app/packs/entrypoints/application.js index 6b669360..6364e9fd 100644 --- a/app/packs/entrypoints/application.js +++ b/app/packs/entrypoints/application.js @@ -17,3 +17,13 @@ import 'bootstrap' Rails.start() ActiveStorage.start() + +// Open all external links in a new window +addEventListener('click', function (event) { + const target = event.target + const el = target.closest('a') + if (el && !el.isContentEditable && el.host !== window.location.host) { + el.setAttribute('target', '_blank') + el.setAttribute('rel', 'noopener noreferrer') + } +}, true) From 1993f6b42badc16b810dbffc0a9236a58f0fe754 Mon Sep 17 00:00:00 2001 From: Jason Yavorska Date: Mon, 3 May 2021 17:38:46 +0200 Subject: [PATCH 2/2] Standard fix --- app/packs/entrypoints/application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/packs/entrypoints/application.js b/app/packs/entrypoints/application.js index 6364e9fd..f77176ad 100644 --- a/app/packs/entrypoints/application.js +++ b/app/packs/entrypoints/application.js @@ -19,7 +19,7 @@ Rails.start() ActiveStorage.start() // Open all external links in a new window -addEventListener('click', function (event) { +window.addEventListener('click', function (event) { const target = event.target const el = target.closest('a') if (el && !el.isContentEditable && el.host !== window.location.host) {