Improve browser/Cordova compatibility

master
Skylar Ittner 2 years ago
parent c68fc954a3
commit fe5a15d566

@ -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); cordovaInAppBrowserRef = cordova.InAppBrowser.open(url, "_blank", options);
if (typeof onclose == "function") { if (typeof onclose == "function") {
try { try {
cordovaInAppBrowserRef.removeEventListener("exit"); cordovaInAppBrowserRef.removeEventListener("exit");
} catch (ex) { } catch (ex) {
}
cordovaInAppBrowserRef.addEventListener("exit", onclose);
}
if (typeof onmessage == "function") {
try {
cordovaInAppBrowserRef.removeEventListener("message");
} catch (ex) {
}
cordovaInAppBrowserRef.addEventListener("message", onmessage);
} }
cordovaInAppBrowserRef.addEventListener("exit", onclose);
} }
if (typeof onmessage == "function") {
try { closeBrowser = function () {
cordovaInAppBrowserRef.removeEventListener("message"); if (typeof cordovaInAppBrowserRef != null) {
} catch (ex) { cordovaInAppBrowserRef.close();
} }
cordovaInAppBrowserRef.addEventListener("message", onmessage);
} }
}
closeBrowser = function () { openExternalBrowser = function (url) {
if (typeof cordovaInAppBrowserRef != null) { window.open(url, '_system', '');
cordovaInAppBrowserRef.close(); }
} else {
// Running in browser, use a "real" window instead of an IAB one
openBrowser = function (url) {
window.open(url);
} }
}
openExternalBrowser = function (url) { openExternalBrowser = function (url) {
window.open(url, '_system', ''); window.open(url);
}
} }
IonicDeeplink.onDeepLink(function (link) { IonicDeeplink.onDeepLink(function (link) {

Loading…
Cancel
Save