Window.open not working


#1

Hi,

I’m using this kind of link in my ionic app:

<a href="#" onClick="window.open('https://google.com', '_system', 'location=yes');return false;">link</a>

It works in a browser, and on my device with “ionic run”.
But it doesn’t work on my client devices, who installed the app with the apk file I generated (using ionic package build android).

I have in my config.xml file:

<access origin="*" launch-external="yes"/>
<allow-navigation href="*"/>

What could be wrong?


#2

To use this functionality on your device you need the cordova inappbrowser, which can be found here. If you use the ngCordova lib, you can also check this documentation for reference. Good luck!


#3

I already installed the cordova inappbrowser plugin.
I just did another test with: $cordovaInAppBrowser.open(…), and it works on my device, with “ionic run”.
But on another device, after an update of the app, nothing happens when I click on my links…
I’m really stuck…


#4

Do you get any error logs in the developers console when debugging the app on that other device?

Maybe this little example will help you out, because you have to specify some more stuff to make it 100% work.

Your HTML:
<a ng-click="open_link($event)" target="_system" href="{{ url }}">link to wherever you wanna go bro</a>

Your controller function:
$scope.open_link = function(event) { var href = event.target.href; var browserRef = window.open(href, '_system', 'location=no,clearsessioncache=no,clearcache=no'); event.preventDefault(); }

(btw why not using ng-click handler instead of onClick?)


#5

@jcmag did you try it out yet?


#6

I have rebuilt the .apk file, and now it works on my customer’s devices. I think the problem was related to the config.xml file (the “allow-navigation” setting ?)


#7

Yes, the intent is important. So it could have been the issue. Glad it works now!


#8

a new issue appeared today:

when I run my app on my device using:
ionic run android
window.open opens the page in Chrome.

but after building an apk file, using:
ionic package build android
window.open opens the page in the inapp browser…

what could change the behavior of window.open?