jQuery doesn't support postmessage event?

前端 未结 2 350
悲哀的现实
悲哀的现实 2021-02-01 12:30

When I use jQuery event listener to handle message event, like below:

$(window).on(\'message\', function(e) {
    var data = e.data; // data = undefined
});
         


        
2条回答
  •  温柔的废话
    2021-02-01 12:30

    Some browsers use the "onmessage" event. I suggest a little improvement to the previous answer for increased compatibility:

    $(window).on("message onmessage", function(e) {
        var data = e.originalEvent.data;
    });
    

提交回复
热议问题