Improve browser/Cordova compatibility

This commit is contained in:
Skylar Ittner 2022-04-03 22:17:18 -06:00
parent c68fc954a3
commit fe5a15d566

View File

@ -176,37 +176,48 @@ function initCordova() {
}, function (err) {}); }, function (err) {});
window.htmlopen = window.open; window.htmlopen = window.open;
window.open = cordova.InAppBrowser.open; if (typeof device != "undefined" && device.platform != "browser") {
window.open = cordova.InAppBrowser.open;
openBrowser = function (url, options, onclose, onmessage) { openBrowser = function (url, options, onclose, onmessage) {
if (typeof options == "undefined") { if (typeof options == "undefined") {
options = "location=yes,fullscreen=no,zoom=no"; options = "location=yes,fullscreen=no,zoom=no";
}
cordovaInAppBrowserRef = cordova.InAppBrowser.open(url, "_blank", options);
if (typeof onclose == "function") {
try {
cordovaInAppBrowserRef.removeEventListener("exit");
} catch (ex) {
} }
cordovaInAppBrowserRef.addEventListener("exit", onclose); cordovaInAppBrowserRef = cordova.InAppBrowser.open(url, "_blank", options);
} if (typeof onclose == "function") {
if (typeof onmessage == "function") { try {
try { cordovaInAppBrowserRef.removeEventListener("exit");
cordovaInAppBrowserRef.removeEventListener("message"); } catch (ex) {
} catch (ex) { }
cordovaInAppBrowserRef.addEventListener("exit", onclose);
}
if (typeof onmessage == "function") {
try {
cordovaInAppBrowserRef.removeEventListener("message");
} catch (ex) {
}
cordovaInAppBrowserRef.addEventListener("message", onmessage);
} }
cordovaInAppBrowserRef.addEventListener("message", onmessage);
} }
}
closeBrowser = function () { closeBrowser = function () {
if (typeof cordovaInAppBrowserRef != null) { if (typeof cordovaInAppBrowserRef != null) {
cordovaInAppBrowserRef.close(); cordovaInAppBrowserRef.close();
}
} }
}
openExternalBrowser = function (url) { openExternalBrowser = function (url) {
window.open(url, '_system', ''); window.open(url, '_system', '');
}
} else {
// Running in browser, use a "real" window instead of an IAB one
openBrowser = function (url) {
window.open(url);
}
openExternalBrowser = function (url) {
window.open(url);
}
} }
IonicDeeplink.onDeepLink(function (link) { IonicDeeplink.onDeepLink(function (link) {