From f7640e867ed1f6409c0f39ad8ede961f400d796d Mon Sep 17 00:00:00 2001 From: Mateusz Narowski Date: Fri, 13 Oct 2023 23:46:40 +0200 Subject: [PATCH] fix: add option to open local links in a new tab (#317) --- lib/components/T3HtmlParser/T3HtmlParser.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/components/T3HtmlParser/T3HtmlParser.vue b/lib/components/T3HtmlParser/T3HtmlParser.vue index a5d04369..61659a48 100644 --- a/lib/components/T3HtmlParser/T3HtmlParser.vue +++ b/lib/components/T3HtmlParser/T3HtmlParser.vue @@ -45,8 +45,12 @@ export default { // If target is still not a link, ignore if (!(target instanceof HTMLAnchorElement)) { return } const href = target.getAttribute('href') - // Get link target, if local link, navigate with router link - if (href && href[0] === '/') { + const hrefTarget = target.getAttribute('target') + const isCtrlKeyPressed = event.ctrlKey || event.metaKey + const openInNewTab = (hrefTarget && hrefTarget === '_blank') || isCtrlKeyPressed + // If link is local, not set to open in a new tab, + // and Ctrl (or Cmd) key is not pressed, navigate with router link + if (href && href[0] === '/' && !openInNewTab) { event.preventDefault() this.$router.push(href) }