jQuery doesn't support postmessage event?

前端 未结 2 353
悲哀的现实
悲哀的现实 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:31

    jQuery might be preprocessing the event's data property, and this operation may not properly support the message event (yet).

    Try using the originalEvent property to fetch your data:

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

提交回复
热议问题