how to identify onbeforeunload was caused by clicking close button

后端 未结 4 1323
囚心锁ツ
囚心锁ツ 2020-12-07 03:08

How do I determine if onbeforeunload was caused by clicking the close button or a page refresh or generally what event caused onbeforeunload?

here is a snippet:

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 03:35

    I searched for something similar but ended up empty handed. So I tried doing the opposit

    We can identify all the events but browser events. Refer below (Untested) snippet.

    var target = $( e.target );
    if(!target.is("a, :button, :submit, :input, .btn, .bulkFormButton")){
    //Your code for browser events)
    }
       $("form").submit(function () {
                 //Your code for browser events)
       });
    

    This worked for me but there are still some events that are not handled. I am in search of those. If anyone have idea about them please share.

提交回复
热议问题