InAppBrowser.open 使用“_system”参数在 webview 中打开链接(仅在 iOS 中)

InAppBrowser.open with "_system" param is opening links inside webview (only in iOS)

从昨天开始,我一直在与 Cordova 应用程序(iOS 和 Android)中的这个奇怪问题作斗争,所以我想是时候寻求一点帮助了。

我在 "deviceready" 事件中有以下代码 运行:

document.addEventListener('deviceready', function() {
    delete window.open;

    $(document).on('mousedown','a', function(e) {
        e.preventDefault();
        if (this.hostname !== window.location.hostname) {
            const url = $(this).attr('href');
            cordova.InAppBrowser.open(url, '_system', 'location=yes');
        }
    });
}, false);

这对 Android 非常有效。在 iOS 中,它会在系统浏览器中打开 link,当我回到我的应用程序时,它也会在那里打开。

为 ios 和 android

试试这个
window.open(urlValue, "_system", "location=yes");

刚刚找到解决方案。问题显然是使用 "mousedown" 事件,切换到 "click" 就可以了。我还必须将 e.preventDefault 调用移动到 if 块,否则内部链接将不起作用。

document.addEventListener('deviceready', function() {
    delete window.open;

    $(document).on('click','a', function(e) {
        if (this.hostname !== window.location.hostname) {
            e.preventDefault();
            const url = $(this).attr('href');
            cordova.InAppBrowser.open(url, '_system', 'location=yes');
        }
    });
}, false);