MOBILE-2650 utils: Fix links inside iframes created after page load
parent
ff08501397
commit
82ca471c5b
|
@ -183,55 +183,49 @@ export class CoreIframeUtilsProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const links = Array.from(contentDocument.querySelectorAll('a'));
|
contentDocument.addEventListener('click', (event) => {
|
||||||
links.forEach((el: HTMLAnchorElement) => {
|
if (event.defaultPrevented) {
|
||||||
const href = el.href;
|
// Event already prevented by some other code.
|
||||||
|
|
||||||
// Check that href is not null.
|
|
||||||
if (href) {
|
|
||||||
const scheme = this.urlUtils.getUrlScheme(href);
|
|
||||||
if (scheme && scheme == 'javascript') {
|
|
||||||
// Javascript links should be treated by the iframe's Javascript.
|
|
||||||
// There's nothing to be done with these links, so they'll be ignored.
|
|
||||||
return;
|
return;
|
||||||
} else if (scheme && scheme != 'file' && scheme != 'filesystem') {
|
}
|
||||||
|
|
||||||
|
// Find the link being clicked.
|
||||||
|
let el = <Element> event.target;
|
||||||
|
while (el && el.tagName !== 'A') {
|
||||||
|
el = el.parentElement;
|
||||||
|
}
|
||||||
|
if (!el || el.tagName !== 'A') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const link = <HTMLAnchorElement> el;
|
||||||
|
|
||||||
|
const scheme = this.urlUtils.getUrlScheme(link.href);
|
||||||
|
if (!link.href || (scheme && scheme == 'javascript')) {
|
||||||
|
// Links with no URL and Javascript links are ignored.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scheme && scheme != 'file' && scheme != 'filesystem') {
|
||||||
// Scheme suggests it's an external resource, open it in browser.
|
// Scheme suggests it's an external resource, open it in browser.
|
||||||
el.addEventListener('click', (e) => {
|
event.preventDefault();
|
||||||
// If the link's already prevented by SCORM JS then we won't open it in browser.
|
|
||||||
if (!e.defaultPrevented) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (!this.sitesProvider.isLoggedIn()) {
|
if (!this.sitesProvider.isLoggedIn()) {
|
||||||
this.utils.openInBrowser(href);
|
this.utils.openInBrowser(link.href);
|
||||||
} else {
|
} else {
|
||||||
this.sitesProvider.getCurrentSite().openInBrowserWithAutoLoginIfSameSite(href);
|
this.sitesProvider.getCurrentSite().openInBrowserWithAutoLoginIfSameSite(link.href);
|
||||||
}
|
}
|
||||||
}
|
} else if (link.target == '_parent' || link.target == '_top' || link.target == '_blank') {
|
||||||
});
|
|
||||||
} else if (el.target == '_parent' || el.target == '_top' || el.target == '_blank') {
|
|
||||||
// Opening links with _parent, _top or _blank can break the app. We'll open it in InAppBrowser.
|
// Opening links with _parent, _top or _blank can break the app. We'll open it in InAppBrowser.
|
||||||
el.addEventListener('click', (e) => {
|
event.preventDefault();
|
||||||
// If the link's already prevented by SCORM JS then we won't open it in InAppBrowser.
|
this.utils.openFile(link.href).catch((error) => {
|
||||||
if (!e.defaultPrevented) {
|
|
||||||
e.preventDefault();
|
|
||||||
this.utils.openFile(href).catch((error) => {
|
|
||||||
this.domUtils.showErrorModal(error);
|
this.domUtils.showErrorModal(error);
|
||||||
});
|
});
|
||||||
}
|
} else if (this.platform.is('ios') && (!link.target || link.target == '_self')) {
|
||||||
});
|
|
||||||
} else if (this.platform.is('ios') && (!el.target || el.target == '_self')) {
|
|
||||||
// In cordova ios 4.1.0 links inside iframes stopped working. We'll manually treat them.
|
// In cordova ios 4.1.0 links inside iframes stopped working. We'll manually treat them.
|
||||||
el.addEventListener('click', (e) => {
|
event.preventDefault();
|
||||||
// If the link's already prevented by SCORM JS then we won't treat it.
|
|
||||||
if (!e.defaultPrevented) {
|
|
||||||
if (element.tagName.toLowerCase() == 'object') {
|
if (element.tagName.toLowerCase() == 'object') {
|
||||||
e.preventDefault();
|
element.setAttribute('data', link.href);
|
||||||
element.setAttribute('data', href);
|
|
||||||
} else {
|
} else {
|
||||||
e.preventDefault();
|
element.setAttribute('src', link.href);
|
||||||
element.setAttribute('src', href);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue