We have a site which is having a strange issue, at least based on my understanding of the onbeforeunload
method. Basically, when the user leaves a page, either by navigating away from it, closing the tab, or closing the browser, an AJAX call needs to be made which releases a lock.
The method is very simple:
window.onbeforeunload = function(e) {
$.ajax({...});
}
(the AJAX call is done synchronously)
We have tested this code and found that if the user closes the specific tab (when there is more than one tab open), the AJAX call works perfectly fine. HoWEVER, if the entire browser is closed, then the code in the onbeforeunload
function does not work as expected (i.e. the page lock remains). We have tested this in both Chrome and Edge and the same thing happens in both browser.
My understanding was that the onbeforeunload
is supposed to fire whenever the page is navigated away from (i.e. clicking a link, closing the tab, or closing the browser). I know there was a caveat about needing to interact with the page at least once, which does happen. I tested it by editing items on the page, and it the issue still persists.
Can anyone offer any insight into why this would be happening? Everything works find if the tab is closed, but the browser remains open, but fails if the browser is closed. Thank you in advance for any information/guidance you can provide.