How to capture browser close event?

后端 未结 4 1200
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 10:18

I want to capture the browser close event in my application and show a confirm box to user. I am using JSF 2.0 and richfaces 4.0.

4条回答
  •  心在旅途
    2020-11-29 10:48

    window.onbeforeunload = function () 
    {
      var shallIAlertUser = Do_Whatever(); //get boolen value
      if (shallIAlertUser) {
        //this will alert user
        return 'Are you sure?';
      }
      else {
        //this wont
        window.onbeforeunload = undefined;
      }
    };
    

提交回复
热议问题