I\'d like to check if the current browser supports the onbeforeunload event. The common javascript way to do this does not seem to work:
if (window.onbeforeu
Mobile browsers don't tend to not support beforeunload because the browser can go into the background without unloading the page, then be killed by the operating system at any time.
However, all modern non-mobile browsers support it. Therefore, you can just check if the browser is a mobile browser.
To solve the problem I use:
var isMobile = navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/iPhone|iPad|iPod/i) || navigator.userAgent.match(/Opera Mini/i) || navigator.userAgent.match(/IEMobile/i);
if (isMobile)
{
window.addEventListener("visibilitychange", function(e)
{
if (document.visibilityState == 'hidden')
{
console.log("beforeunload");
location.reload();
}
});
}
else
{
window.addEventListener("beforeunload", function(e)
{
console.log("beforeunload");
});
}