From 6648b5e6191f90ab52a39cc6f28b162a8fb59b0c Mon Sep 17 00:00:00 2001 From: Adrian Vollmer Date: Mon, 22 Apr 2024 20:41:34 +0200 Subject: [PATCH] Fix fixLinks Don't touch links starting with `javascript:` --- zundler/assets/zundler_common.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zundler/assets/zundler_common.js b/zundler/assets/zundler_common.js index 4726c49..0eb5fbc 100644 --- a/zundler/assets/zundler_common.js +++ b/zundler/assets/zundler_common.js @@ -44,14 +44,18 @@ var splitUrl = function(url) { var fixLink = function(a) { - if (isVirtual(a.getAttribute('href'))) { + const href = a.getAttribute("href"); + if (isVirtual(href)) { // virtualClick will be defined in the iFrame, but fixLink may be // called in the parent document, so we use `onclick`, because we // can define the function as a string a.setAttribute("onclick", "virtualClick(event)"); - } else if (a.getAttribute('href').startsWith('#')) { + } else if (href.startsWith('#')) { a.setAttribute('href', "about:srcdoc" + a.getAttribute('href')) - } else if (!a.getAttribute('href').startsWith('about:srcdoc')) { + } else if ( + !href.startsWith('about:srcdoc') + && !href.startsWith('javascript:') + ) { // External links should open in a new tab. Browsers block links to // sites of different origin within an iframe for security reasons. a.setAttribute('target', "_blank");