javascript - onBeforeUnload event to create this? -


enter image description here

i searching exemple of want, , stackoverflow gave me one. want reproduce above , i'm pretty sure unbeforeunload event. used 2 code below no succes... wonder why.

<script language="javascript" type="text/javascript">  $(window).bind('beforeunload', function () {      if (confirm("vous alliez quitter sans sauvegarder. voulez-vous sauvegarder maintenant ?") == true) {         document.getelementbyid('<%= btnenregistrer.clientid %>').click();     } });  //dosen't work  window.onbeforeunload = confirmexit; function confirmexit() {     if (confirm("vous alliez quitter sans sauvegarder. voulez-vous sauvegarder maintenant ?") == true) {         document.getelementbyid('<%= btnenregistrer.clientid %>').click();     } }  //dosen't work...... 

you can achieve passing method directly onbeforeunload state of window object

window.onbeforeunload = function(e) {     e = e || window.event;     e.preventdefault = true;     e.cancelbubble = true;     e.returnvalue = 'your beautiful goodbye message'; } 

or use addeventlistener handler:

window.addeventlistener('beforeunload', function(e) {     e = e || window.event;     e.preventdefault = true;     e.cancelbubble = true;     e.returnvalue = 'your beautiful goodbye message'; }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -