【问题标题】:postMessage in beforeunload failsbeforeunload 中的 postMessage 失败
【发布时间】:2017-04-20 17:46:45
【问题描述】:

我看到,当在 Ionic 2 浏览器的 beforeunload 窗口事件中调用 postMessage() 时,消息永远不会到达父级。如果在unloadload 事件中发布相同的消息,则成功接收。在 JQuery 中:

$(window).on('beforeunload', function() {
    parent.postMessage('TheMessage', 'domain.com');  //NOT received by parent
});     

$(window).on('unload', function() {
    parent.postMessage('TheMessage', 'domain.com');  //Received by parent
});

$(window).load(function(){
    parent.postMessage('TheMessage', 'domain.com');  //Received by parent
});

在这种情况下,我们从 IFrame 向父级发布,两个网页由同一所有者控制,但来自不同的域。

这是预期的行为吗?我看到了alert is not allowed in beforeunload,但没有看到关于postMessage 的任何规则:

自 2011 年 5 月 25 日起,HTML5 规范规定调用 window.alert()、window.confirm() 和 window.prompt() 方法可能是 在此事件期间被忽略。

有没有办法在beforeunload中使用postMessage

【问题讨论】:

    标签: javascript events iframe ionic2 message


    【解决方案1】:

    这只发生在 iOS 中,似乎没有办法改变它。在 Android 中,beforeunload 会按预期触发。

    【讨论】:

      猜你喜欢
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 2022-10-13
      • 2013-11-28
      • 2018-02-05
      • 1970-01-01
      相关资源
      最近更新 更多