Software Archive
Read-only legacy content
17061 Discussions

how to show message if inAppBrowser failed?

Osama_R_
Novice
839 Views

hi guys,

anyone know how to show message if inAppBrowser failed?

 

i mean if no connection per example, how to redirect to another webpage?

 

Thanks.. :)

0 Kudos
1 Reply
Dale_S_Intel
Employee
839 Views

It looks like InAppBrowser varies from typical plugins in a couple ways.  First' it starts with a Capital letter.   More relevant is the fact that unlike most Cordova plugins, rather than taking 'success' and 'fail' callbacks, it relies on events.  I'm guessing this is because it's trying to be a "drop-in replacement for the window.open() function".  Thus as soon as you open the new window, you can set an event listener to catch an error:

x = cordova.InAppBrowser.open('https://bad.url.com', '_blank');
x.addEventListener('loaderror', function () {alert("ERROR");});

I don't know if there may be synch problems with this (i.e. addEventListener doesn't execute until after 'loaderror' fires) but it seemed to work for me in the debugger.

There are several other events as well. You can find more details here:

https://www.npmjs.com/package/cordova-plugin-inappbrowser

Good luck, and let us know if that works.

Dale

 

0 Kudos
Reply