[removed] and [removed] is not working in Firefox , Safari , Opera?

后端 未结 6 1948
心在旅途
心在旅途 2020-11-22 12:11

In my chat application I need to get confirmation from user , when my application closes.

So I used the window.onbeforeunload for confirmation alert and

6条回答
  •  面向向阳花
    2020-11-22 12:45

    Here is the working solution for ie, firefox and chrome:

    var myEvent = window.attachEvent || window.addEventListener;
    var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
    
                myEvent(chkevent, function(e) { // For >=IE7, Chrome, Firefox
                    var confirmationMessage = 'Are you sure to leave the page?';  // a space
                    (e || window.event).returnValue = confirmationMessage;
                    return confirmationMessage;
                });
    

提交回复
热议问题