How can I open an external link in Safari not the app's UIWebView?

后端 未结 10 1411
甜味超标
甜味超标 2020-11-28 10:47

I have a Phonegap (cordova) application where I want to load some external webpages within the phonegap WebView and I have other external webpages that I want to load in saf

10条回答
  •  Happy的楠姐
    2020-11-28 11:05

    The right way of doing this is using the inAppBrowser plugin

    install it using the cordova CLI:

    cordova plugin add org.apache.cordova.inappbrowser
    

    Then, to open a link on safari just use:

    window.open('http://apache.org', '_system');
    

    There is a newer version of the plugin hosted on npm

    to install it from the cordova CLI:

    cordova plugin add cordova-plugin-inappbrowser
    

    To open the website on safari you can use

    cordova.InAppBrowser.open('http://apache.org', '_system');
    

    or, if you want to continue using window.open like the older version you can just do this on device ready event:

    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        window.open = cordova.InAppBrowser.open;
    }
    

提交回复
热议问题