Skip to content

Instantly share code, notes, and snippets.

Last active December 9, 2019 16:34
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JonathanHindi/6301111 to your computer and use it in GitHub Desktop.
[PhoneGap] Open any external link inside PG inAppBrowser
/* Handle any link start with http or https using PhoneGap (Cordova) inAppBrowser
* Options you can set data-in-app-browser html attribute to one of the
* following options:
* _self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser
* _blank - always open in the InAppBrowser
* _system - always open in the system web browse
$(document).on('click', 'a[href^=http], a[href^=https]', function(e){
var $this = $(this);
var target = $'inAppBrowser') || '_blank';$this.attr('href'), target, 'location=no');
Copy link

Thanks !

Copy link

Dumb question, but... how exactly do I call this into my Ionic project? I get that I should create the js file, reference it in index.html, but any other code I need to add to the above to make it update all my links to open in the inAppBrowser?


Copy link

Hi I ran into a similar problem because download links (e.g. .pdf) don't work in inAppBrowser, I finally found a working solution with inAppBrowser 3.1.0 using beforeload event:

Perhaps my solution helps you or others. I also lost several hours on this.
All things I tried in the loaded website itself didn't succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment