【问题标题】:window.postMessage in ionic typescript离子打字稿中的 window.postMessage
【发布时间】:2019-02-19 15:22:36
【问题描述】:

我有这个在 web 中可以正常工作的 postmessage javascript 代码:

<script>
    var popup;
    window.addEventListener('message', function(e) {  
              console.log(e.origin);    
            if (popup != null) {
                var reply = JSON.stringify( {'msg' : 'Message' } );
                popup.postMessage(reply, e.origin);
            }
        });
    function openRemotePage() {
        popup = window.open('website.com' );
    }
</script>

我想在 Ionic-typescript 中拥有类似的功能。

【问题讨论】:

    标签: javascript typescript ionic-framework postmessage


    【解决方案1】:
      public static popup:any;
      public openRemotePage():void{
        window.addEventListener('message', function(e) {
        var msg = JSON.parse(e.data);
        if (MyModal.popup!= null) {
            var reply = JSON.stringify( {'msg' : 'Message' } );
            MyModal.popup.postMessage(reply, e.origin);
        }
      });
      MyModal.popup = window.open('website.com');
      }
    

    【讨论】:

      猜你喜欢
      • 2019-01-24
      • 2018-07-25
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多