I am trying to open an external url link in my app which is a cordova app. Right now its presents an in app browser using modal view but it has NO back button or close button. The user essentially gets stuck when they click an external link. For instance, when someone clicks this link, enclosed in "Visit Website", an in app browser shows up, the website shows up fine, BUT there is no way to navigate back to the app, or close the in app browser. How do I go about fixing this?
<a href="http://www.sdtaproom.com/" target="_blank">Visit Website</a>
I saw that there is a solution, window.open("http://stackoverflow.com", "_system");, but I don't know how to implement it in the href code.
ANSWER (Edited): Add this code in the script tag in the head.
<script src="cordova.js"></script>
<script type="text/javascript">
window.addEventListener('load', function () {
$(document).on('click', 'a[target="_system"],a[target="_blank"]', function (e) {
e.preventDefault();
var url = this.href;
window.open(url,"_system");
});
}, false);
</script>
You can embed javascript code in the href
attribute. This should do the trick:
<a href="javascript: window.open('http://www.sdtaproom.com/', '_system'); return false;">Visit Website</a>
You will also have to install the InAppBrowser plugin (don't be fooled by its name).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With