0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cordova-plugin-inappbrowserの"message"イベント

Posted at

cordova-plugin-inappbrowser "message"イベントでネイティブ側で処理

非常に役に立つ"message"イベント。
これを使えばinappbrowser側でのイベントをひっかけてネイティブにもってこれる。
cordova側の処理。

    this.Ref.addEventListener("message", function(event){
        var type = event.type;
    });

とても楽。

呼び出す側。

    if (window.webkit && window.webkit.messageHandlers) {

            var messageObj = {
                    "type": type
                    , "data" : data
            };
            var stringifiedMessageObj = JSON.stringify(messageObj);
            webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);
    }

とても楽。
渡すパラメータはjsonにしてやるみたいでござるよ。

注意すべきはAndroid時の挙動か。
window.webkitはネイティブ側のonなんたらFinishイベントで捏造しているくさい。
document.readyとかでイベントはしらせたら多分はしらない。たぶんね。
(cordova_iabというオブジェクトを直で使えば動かせるかも)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?