As answered in other posts, you have two different options for different platforms. What I do is:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
// Mock device.platform property if not available
if (!window.device) {
window.device = { platform: 'Browser' };
}
handleExternalURLs();
}
function handleExternalURLs() {
// Handle click events for all external URLs
if (device.platform.toUpperCase() === 'ANDROID') {
$(document).on('click', 'a[href^="http"]', function (e) {
var url = $(this).attr('href');
navigator.app.loadUrl(url, { openExternal: true });
e.preventDefault();
});
}
else if (device.platform.toUpperCase() === 'IOS') {
$(document).on('click', 'a[href^="http"]', function (e) {
var url = $(this).attr('href');
window.open(url, '_system');
e.preventDefault();
});
}
else {
// Leave standard behaviour
}
}
So as you can see I am checking the device platform and depending on that I am using a different method. In case of a standard browser, I leave standard behaviour. From now on the solution will work fine on Android, iOS and in a browser, while HTML page won't be changed, so that it can have URLs represented as standard anchor
<a href="http://stackoverflow.com">
The solution requires InAppBrowser and Device plugins