Calling JS functions on browser tab close

后端 未结 3 2031
忘掉有多难
忘掉有多难 2020-12-07 03:10

\"enterI need to call a JS function when user closing the browser tab. the problem is i want t

3条回答
  •  借酒劲吻你
    2020-12-07 04:03

    JSFiddle uses the following to alert the user they are trying to close their modified fiddle without saving:

    window.onbeforeunload = function(){
      if (window.editorsModified){
        return "You've modified your fiddle, reloading the page will reset all changes."
      }
    };
    

    This works reliably (http://jsfiddle.net/MaxPRafferty/b6uEF/show/ ,Latest Chrome, FF, IE10 ), but will always prompt the user. You can't force the page open by returning false;

提交回复
热议问题