inappbrowser plugin behaving differently on ios?

  • 1
  • Question
  • Updated 5 years ago
  • Doesn't Need an Answer
Hi everyone,

I just have a quick question about the inappbrowser plugins. What I am trying to achieve is load a webpage in my app (ios and android), and then close the inapp browser.

I tried org.li8.inappbrowser as well as org.apache.plugin.inappbrowser. Thanks to the information from this post ( http://stackoverflow.com/questions/15... ) I can close it as well on Android from a button on my webpage. Now, I have two minor issues with ios.

1. a bottom bar with a done action appears and I would like to remove it.
2. for some reason I cannot recognise the loadstart or loadstop event.

I was wondering if someone might have an hint for me.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes

Posted 5 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Two hints:
1. You can get rid of that done button by including "location=no" in the options parameter of the open() function
2. You should use the new inappbrowser plugin from npm (https://www.npmjs.com/package/cordova...)
Be aware that the open() call is different.

If you can't catch the loadstart/stop events "for some reason", it would not be a bad idea to find out what that reason is. (Without you posting the code you are using, there's no way a denizen in this forum can tell).
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
Thank you this npm plugin gives the same experience on both ios and Android. Much appreciated.

I just need to figure out how to close the inappbrowser from my webpage now (from a link or input button).

I would like something like:
var ref = cordova.InAppBrowser.open(encodeURI($('#button').attr('href')), '_blank', 'location=no');
ref.addEventListener('loadstop', function (event) {
if (event.url.match("mobile/close")) {
ref.close();
}
});

And a link in my page test
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
ahah, window.open = cordova.InAppBrowser.open; cordova is not defined. This is my issue. It is not initializing in my deviceready section.

Are there known issues with the 3.7.0 framework?
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
Even though the javascript file is pulled in, cordova is not defined.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I'd need to see your code. Are you using the cordova object before deviceready has fired?
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
Hi Petra, first of all thank you for the help. This plugin has gotten me reasonably frustrated to be honest and I apologies for forgetting common courtesy in my previous couple of posts ^.^'

Here is an extract from my app.js file (would you like to see more?):

function onDeviceReady() {
config.platform = device.platform; //this works fine

window.open = cordova.InAppBrowser.open;

etc ...
}

I tried to follow the documentation. I never use the cordova object before which conduses me. onDeviceReady seems to be triggering fine, as I do a few more things in there.

I was wondering for a moment whether this npm plugin does not suit well with PGB, but I have yet to try a local build (we are trying to stay away from that as with multiple developer PGB's 'simplicity' is attractive). I tried the latest cordova framework too, to no avail i'm afraid.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Two thoughts, here:
1. Make sure you actually have the plugin included. One typo could make all the difference. So please, check the plugins tab of your app's PGB page to see if that plugin is listed
2. If it is, then please add this:
alert("IAB=" + typeof cordova.InAppBrowser); in your onDeviceReady for test purposes
A while ago, someone reported that the cordova object would return 'undefined' but 'cordova.InAppBrowser' was a defined object. Yes, that would be very strange, but should be investigated.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
Cheers,

I can guarantee 1. as I checked earlier on today.

I will try 2. first thing in the morning when I'm back in the office.

Have a pleasant day.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
Catch you tomorrow, I ended up checking quickly as I'm not setup for full on debug here. IAB=Object is what the alert returns.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
You mean that my cordova undefined error on window.open = cordova.InAppBrowser.open; is a red herring then? If so brilliant I'll carry on debugging when I get up.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Not 100% sure, but it looks like that, yes.
If I were you, I would carry on and see what your attempts result in, right now. For instance, you should check the event.url.match("mobile/close") value closely.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
My work test device is running cyanogenmod (IAB=undefined on this one). I hope I dont have enough customers using this to warrant a fix. I'll look into it. Have a good weekend, and cheers again.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
Basically fails on all Android 4.4 from my testing last week, just thought I would put this out there.
Photo of Alex Heitz

Alex Heitz

  • 26 Posts
  • 2 Reply Likes
And the fix for 4.* androids is to turn hydra off... Rookie mistake. Once again thanks for the support Petra. Hope I can return the favour in kind.