Sunday, December 1, 2013

Understanding logic of cordova inappbrowser plugin

When inappbrowser plugin open method is called to open a new url,  the plugin native code will create a new webview and set its delegate to a new webview's controller to handle the url loading event. So there will be two different web views existing, once for the original html page and one for the inappbrowser url.

Once the inappbrowser url is loaded, the inappbrowser's webview didStartLoad and didFinishLoad event will be called, the inappbrowser native code will report the event as plugin callback to javascript. Note as the original plugin method was called on the original html page, so the plugin js callback onloadstart, onloadstop will also be invoked on the original plugin js method implemented on original html page.

In addition, since the onloadstart or onloadstop was triggered by url loading system from inappbrowser webview, so those events will be fired again whenever the inappbrowser loads an new url after the initial open url is loaded, so if you click a link in inappbrowser's html page to load another url, then the onloadstart and onloadstop events will be fired again for the new url

The html content shown in the inappbrowser webview really does not matter, it can be a simple html page or a text file, which has nothing to do with cordova, although it should also work if a cordova app is loaded.

Certainly on exit event will only be fired once when the inappbrowser is closed.

No comments:

Post a Comment