Skip to content

Commit 5a65bb7

Browse files
committed
fix: prevent event propagation
1 parent 4205d0a commit 5a65bb7

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/lib/functions/protoHTMLconversion/transformAnchors.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ export function transformAnchors(html, refDocument = null) {
99

1010
// Update <a> elements
1111
container.querySelectorAll('a').forEach((a) => {
12-
if (!refDocument || a.getAttribute('document') !== refDocument){
13-
if (!a.hasAttribute('target')) a.setAttribute('target', '_blank');
12+
// prevent event propagation
13+
a.setAttribute('onclick', 'event.stopPropagation();');
14+
15+
// open documents to *other* documents in new tab
16+
if (!refDocument || a.getAttribute('document') !== refDocument) {
1417
if (!a.hasAttribute('rel')) a.setAttribute('rel', 'noopener noreferrer');
18+
if (!a.hasAttribute('target')) a.setAttribute('target', '_blank');
1519
}
20+
21+
// add base path to href
1622
const orig = a.getAttribute('href');
1723
if (orig && orig.startsWith('/')) {
1824
a.setAttribute('href', base + orig);

0 commit comments

Comments
 (0)