From 51906f275ca2ede92090954baafd438c11c20797 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 10 May 2021 08:16:05 +0200 Subject: [PATCH] MOBILE-3701 iframe: Ignore links with href=# --- src/assets/js/iframe-treat-links.js | 8 ++++++-- src/core/services/utils/iframe.ts | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/assets/js/iframe-treat-links.js b/src/assets/js/iframe-treat-links.js index c585c96fe..abded2658 100644 --- a/src/assets/js/iframe-treat-links.js +++ b/src/assets/js/iframe-treat-links.js @@ -187,7 +187,11 @@ context: 'iframe', action: 'link_clicked', frameUrl: location.href, - link: {href: link.href, target: link.target}, + link: { + href: link.href, + target: link.target, + originalHref: link.getAttribute('href'), + }, }, '*'); } @@ -207,4 +211,4 @@ return concatenatePaths(pathToDir, url); } -})(); \ No newline at end of file +})(); diff --git a/src/core/services/utils/iframe.ts b/src/core/services/utils/iframe.ts index 35e17cfbb..1aa40105a 100644 --- a/src/core/services/utils/iframe.ts +++ b/src/core/services/utils/iframe.ts @@ -427,13 +427,13 @@ export class CoreIframeUtilsProvider { /** * A link inside a frame was clicked. * - * @param link Data of the link clicked. + * @param link Link clicked, or data of the link clicked. * @param element Frame element. * @param event Click event. * @return Promise resolved when done. */ protected async linkClicked( - link: {href: string; target?: string}, + link: CoreIframeHTMLAnchorElement | {href: string; target?: string; originalHref?: string}, element?: HTMLFrameElement | HTMLObjectElement, event?: Event, ): Promise { @@ -443,7 +443,8 @@ export class CoreIframeUtilsProvider { } const urlParts = CoreUrl.parse(link.href); - if (!link.href || !urlParts || (urlParts.protocol && urlParts.protocol == 'javascript')) { + const originalHref = 'getAttribute' in link ? link.getAttribute('href') : link.originalHref; + if (!link.href || !originalHref || originalHref == '#' || !urlParts || urlParts.protocol == 'javascript') { // Links with no URL and Javascript links are ignored. return; }