I\'m trying to open links in Safari (on an iPhone) from a PhoneGap application. I\'m using PhoneGap version 3.1.0, and use PhoneGap Build, to build the application.
This is how i solved in Cordova/Phonegap 3.6.3
Install the inappbroswer cordova plugin:
cordova plugin add org.apache.cordova.inappbrowser
I wanted to keep my phonegap app as similar as possible to a standard web page: I wanted that by having target="_blank" on a link, it would open in an external page.
This is how i implemented it:
$("a[target='_blank']").click(function(e){
e.preventDefault();
window.open($(e.currentTarget).attr('href'), '_system', '');
});
so all i have to do is use a link like the following
<a href="http://www.example.com" target="_blank">Link</a>
Late answer but maybe it will be helpful for someone. So what I have in my working code in both iOS and Android application based on Cordova. To open external link in the default browser (Safari or Google):
1) Make sure that you have inAppBrowser plugin
cordova plugin add cordova-plugin-inappbrowser --save
2) Add to device.js
function openURL(urlString){
let url = encodeURI(urlString);
window.open(url, '_system', 'location=yes');
}
3) Create new link
<a href="#" onClick="openURL('http://www.google.com')">Go to Google</a>
For those that didn't spot it in the original question you also need to make sure the URL you are trying to open isn't whitelisted by adding an access tag to your config.xml as follows:
<access origin="http://www.example.com" />
or you can do
<access origin="*" />
to allow anything
try with this below example.
<a class="appopen" onClick="OpenLink();">Sign in</a>
<script>
function OpenLink(){
window.open("http://www.google.com/", "_system");
}
</script>
add this Below line in config.xml if you are using PhoneGap Version 3.1 or above
<gap:plugin name="org.apache.cordova.inappbrowser" />