I need to execute some code before leaving the browser, I implemented this:
window.onbeforeunload = function () { return 'Are you sure?'; };
window.onunload = function () { releaseLocking(); };
It works pretty well with Google Chrome. When closing GC: a message is shown,
- if I click on the button 'stay on the page', nothing will happen. Perfect.
- if I click on the button 'leave the page', the code under releaseLocking will be executed. Perfect.
I have problems with Internet Explorer.
- if I click on the button 'stay on the page', nothing will happen. Perfect.
- if I click on the button 'leave the page', the code under releaseLocking won't get executed.
Any idea?
I searched a lot but didnt found a solution.
Thanks.
UPDATE
var releaseLocking = function() {
// Release only if lock is set on the current user
if (transport().lockedById() == 5) { // 5 is dummy (Jean Dupont for testing)
transport().lockedById(null);
transport().lockedTime(null);
return ctxTransport.saveChanges(SILENTSAVE);
}
};