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:
<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>
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
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
Trying to simplify the solution, this is what I ended up with, using PhoneGap/Cordova 2.5.0 and jQuery 1.9.1
<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");
});
Had the same problem after upgrading to Cordova 1.6.1.
Try adding
target="_blank"
to your links.
That did the trick for me.
This is the 100% guaranteed solution if you are using Phonegap (tested in iOS 6).
To open external URL in Safari, do following:
http://google.com/
Cordova.plist
or Phonegap.plist
, change OpenAllWhitelistURLsInWebView
from Yes
to No
.In your application, add target="_blank"
to your link. Example:
<a href="http://google.com" target="_blank">Google.com</a>
Thank you.