Det*_*ned 5 ios phonegap-plugins cordova hybrid-mobile-app ionic-framework
我正在使用此模块(https://github.com/apache/cordova-plugin-inappbrowser)来打开Cordova应用程序中的外部链接。但是,postMessage文档中的示例不起作用。
我需要能够使inappbrowser实例与父代(opener)通信的能力。鉴于,没有opener对象,因此inappbrowser我仔细阅读了repo的文档和测试,并且无法重现postMessageAPI以在inappbrowser实例与主Cordova应用程序(父代)之间进行通信。
这是此仓库中的文档/测试中的一个简单示例:
const ref = cordova.InAppBrowser.open('http://www.google.com', '_blank');
ref.addEventListener('loadstop', () => {
console.log('loadstop has been fired'); // this fires
// when this has been executed, `webkit` variable doesn't exist inside of the `inappbrowser`
// instance
ref.executeScript({
code: `(() => {
var message = "TESTING!!!";
webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));
})()`
});
});
// this is never fired
ref.addEventListener('message', (...args) => {
console.log('MESSAGE RECEIVED FROM IN_APP_BROWSER', ...args);
});
Run Code Online (Sandbox Code Playgroud)