From 7261841edd4d2fd1353340c4eb198be84bf879e1 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 23 Nov 2018 13:22:54 +0100 Subject: [PATCH] MOBILE-2752 iframe: Handle window.open with target _self --- src/providers/utils/iframe.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/providers/utils/iframe.ts b/src/providers/utils/iframe.ts index 23c83ff70..6771a6ed1 100644 --- a/src/providers/utils/iframe.ts +++ b/src/providers/utils/iframe.ts @@ -195,7 +195,7 @@ export class CoreIframeUtilsProvider { redefineWindowOpen(element: any, contentWindow: Window, contentDocument: Document): void { if (contentWindow) { // Intercept window.open. - contentWindow.open = (url: string): Window => { + contentWindow.open = (url: string, target: string): Window => { const scheme = this.urlUtils.getUrlScheme(url); if (!scheme) { // It's a relative URL, use the frame src to create the full URL. @@ -216,7 +216,14 @@ export class CoreIframeUtilsProvider { } } - if (url.indexOf('cdvfile://') === 0 || url.indexOf('file://') === 0) { + if (target == '_self') { + // Link should be loaded in the same frame. + if (element.tagName.toLowerCase() == 'object') { + element.setAttribute('data', url); + } else { + element.setAttribute('src', url); + } + } else if (url.indexOf('cdvfile://') === 0 || url.indexOf('file://') === 0) { // It's a local file. this.utils.openFile(url).catch((error) => { this.domUtils.showErrorModal(error);