离子打字稿中的window.postMessage

时间:2019-02-19 15:22:37

标签: javascript typescript ionic-framework 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打字稿中具有类似的功能。

1 个答案:

答案 0 :(得分:0)

  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');

}