[removed] executed on page refresh instead of on page close

前端 未结 4 1681
刺人心
刺人心 2020-12-19 01:41

I\'m using window.onbeforeunload to pop up a confirm dialog when a close event occurs, but the confirm dialog appears on page refresh and doesn\'t execute on pa

4条回答
  •  佛祖请我去吃肉
    2020-12-19 01:57

    Try this it will work. You were assigning the method to onload that need to execute when it event occur so its need to be like object. refer link for better explanation - var functionName = function() {} vs function functionName() {}

     window.onbeforeunload = confirmWinClose;
     function confirmWinClose () {
     var confirmClose = confirm('Close?');
     return confirmClose;
     };
    

提交回复
热议问题