PhoneGap: Opening external URL's in Safari

后端 未结 12 867
耶瑟儿~
耶瑟儿~ 2020-11-30 03:04

I\'ve just upgraded to PhoneGap 1.6.1 and I can no longer get external URL\'s to open in Safari.

Prior to this version I had patched AppDelegate.m as follows:

<
相关标签:
12条回答
  • 2020-11-30 03:54

    I managed to make it work with this setup:

    1: Add the following line to config.xml - PhoneGap version 3.1 and above:

    <gap:plugin name="org.apache.cordova.inappbrowser" />
    

    2: Afterwards you can do like this:

    <a onclick="window.open("http://www.yoururl.com/", "_system");">Link</a>
    
    0 讨论(0)
  • 2020-11-30 03:57

    In earlier version of cordova you can load a url in browser by adding target="_blank" to your links. But now you can use inApp browser feature.

    var ref = window.open(encodeURI('your url'), '_system', 'location=no');
    

    This opens the url in browser. Tested in Android and iPhone with cordova2.7.0

    0 讨论(0)
  • 2020-11-30 03:57

    Using Phonegap / Cordova 1.7 I've been able to open URLs in the external Browser in JavaScript just by doing this:

    window.location.href = "http://www.google.com";
    

    I also have OpenAllWhitelistURLsInWebView set to NO in Cordova.plist

    0 讨论(0)
  • 2020-11-30 03:59

    Trying to simplify the solution, this is what I ended up with, using PhoneGap/Cordova 2.5.0 and jQuery 1.9.1

    • OpenAllWhitelistURLsInWebView doesn't matter. Setting it to true, false or omitting it doesn't seem to have any bearing on the result.
    • The URL has a target of _system, like so: <a target="_system" href="https://rads.stackoverflow.com/amzn/click/com/B009CZICQ8" rel="nofollow noreferrer">
    • I then call:

      $("a[target='_system']").click(function(event) {
      
          event.preventDefault();
          window.open($(this).attr("href"), "_system");
      });
      
    0 讨论(0)
  • 2020-11-30 04:01

    Had the same problem after upgrading to Cordova 1.6.1.

    Try adding target="_blank" to your links.

    That did the trick for me.

    0 讨论(0)
  • 2020-11-30 04:04

    This is the 100% guaranteed solution if you are using Phonegap (tested in iOS 6).

    To open external URL in Safari, do following:

    1. Add your link in External Host (white list). e.g.: http://google.com/
    2. In Cordova.plist or Phonegap.plist, change OpenAllWhitelistURLsInWebView from Yes to No.
    3. In your application, add target="_blank" to your link. Example:

      <a href="http://google.com" target="_blank">Google.com</a>
      

    Thank you.

    0 讨论(0)
提交回复
热议问题