javascript - onBeforeUnload event to create this? -
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
Post a Comment