From 2b60aa3370d25a6360cafb91ceea282e9d9e71ba Mon Sep 17 00:00:00 2001 From: Andrea Vettore Date: Wed, 10 Nov 2021 21:12:49 +0100 Subject: [PATCH 1/3] feat(external-link): adding target attributes --- lib/templates/plugin.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/templates/plugin.js b/lib/templates/plugin.js index 5421073..7496a02 100644 --- a/lib/templates/plugin.js +++ b/lib/templates/plugin.js @@ -19,6 +19,11 @@ export default ({ app: { router } }) => { const addListeners = links => { for (let i = 0; i < links.length; i++) { + + if (links[i].hostname != window.location.hostname) { + links[i].target = '_blank'; + } + const target = links[i].getAttribute('target') // For improved security `rel="noopener"` will be added automatically if target is `_blank` From 47ce190157eb24da4ee5c79d347760a2968a283d Mon Sep 17 00:00:00 2001 From: Andrea Vettore Date: Thu, 11 Nov 2021 22:30:07 +0100 Subject: [PATCH 2/3] fix(external-link): use Strict inequality --- lib/templates/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/templates/plugin.js b/lib/templates/plugin.js index 7496a02..42d11c8 100644 --- a/lib/templates/plugin.js +++ b/lib/templates/plugin.js @@ -20,7 +20,7 @@ export default ({ app: { router } }) => { const addListeners = links => { for (let i = 0; i < links.length; i++) { - if (links[i].hostname != window.location.hostname) { + if (links[i].hostname !== window.location.hostname) { links[i].target = '_blank'; } From 2ae9b9c5bc7e73031925b6c3e19f51812d1037fb Mon Sep 17 00:00:00 2001 From: Andrea Vettore Date: Thu, 11 Nov 2021 22:32:02 +0100 Subject: [PATCH 3/3] feat(external-link): check target --- lib/templates/plugin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/templates/plugin.js b/lib/templates/plugin.js index 42d11c8..0891cb6 100644 --- a/lib/templates/plugin.js +++ b/lib/templates/plugin.js @@ -20,12 +20,12 @@ export default ({ app: { router } }) => { const addListeners = links => { for (let i = 0; i < links.length; i++) { - if (links[i].hostname !== window.location.hostname) { - links[i].target = '_blank'; - } - const target = links[i].getAttribute('target') + if (links[i].hostname !== window.location.hostname && !target) { + links[i].target = '_blank'; + } + // For improved security `rel="noopener"` will be added automatically if target is `_blank` // https://github.com/mathiasbynens/rel-noopener/ if (target && target === '_blank') {