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.
I adapted pastullo's answer to work also in a WebApp that might be opened in a cordova InAppBrowser, but also als plain Web-App (e.g. for testing):
function initOpenURLExternally() {
$("a[target='_blank'],a[target='_system']").each(function (i) {
var $this = $(this);
var href = $this.attr('href');
if (href !== "#") {
$this
.attr("onclick", "openURLExternally(\"" + href + "\"); return false;")
.attr("href", "#");
}
});
}
function openURLExternally(url) {
// if cordova is bundeled with the app (remote injection plugin)
log.trace("openURLExternally: ", url);
if (typeof cordova === "object") {
log.trace("cordova exists ... " + typeof cordova.InAppBrowser);
if (typeof cordova.InAppBrowser === "object") {
log.trace("InAppBrowser exists");
cordova.InAppBrowser.open(url, "_system");
return;
}
}
// fallback if no cordova is around us:
//window.open(url, '_system', '');
window.open(url, '_blank', '');
}