代码之家  ›  专栏  ›  技术社区  ›  Detuned

无法将邮件从inappbrowser发送到Cordova应用程序

  •  2
  • Detuned  · 技术社区  · 7 年前

    https://github.com/apache/cordova-plugin-inappbrowser )在我的Cordova应用程序中打开外部链接的能力。然而, postMessage 文档中的示例不起作用。

    inappbrowser 实例来与父对象通信 opener ). 考虑到没有 对象与 应用浏览器 ,我查阅了回购的文件和测试,我无法复制 邮递 用于在 应用浏览器 实例和主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);
    });
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   Detuned    7 年前

    文档指向一个尚未发布的版本。我指了指 3.1.0-dev 这个包的版本和实现就像一个魅力。

        2
  •  -1
  •   andreszs    7 年前

    是的,InAppBrowser还没有 邮递 实施。在这种情况下,唯一的解决方案是使用 iframe公司 从外部网页接收邮件。 This has been discussed earlier 也在这个网站上。