Google chrome onbeforeunload wrong behavior with iframe

前端 未结 3 690
独厮守ぢ
独厮守ぢ 2021-02-13 20:18

Let say I have two pages. One of them contains another one inside as iframe. If you subscribe to onbeforeunload event on the parent page, then this event doesn\'t triggers if yo

3条回答
  •  星月不相逢
    2021-02-13 20:41

    You may also try to change the iframe's url to "about:blank", e.g.:

    $("#myFrameId")[0].src = "about:blank";
    

    It forces chrome to "cleanly" close the window containted within the iframe.

    Just to mention: if you want to close only your iframe but not the parent window, you have to give chrome enough time to execute the handler you've attached to 'onbeforeunload'.

提交回复
热议问题