function isEventTriggeredByLink(event) {
var activeElement = document.activeElement;
return activeElement && activeElement.tagName === 'A';
}
$(window).on('beforeunload', function (event) {
if (!isEventTriggeredByLink(event)) {
showLoadingScreen();
}
});
$(window).on('pagehide', function (event) {
if (!isEventTriggeredByLink(event)) {
showLoadingScreen();
}
});
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden') {
showLoadingScreen();
} else if (document.visibilityState === 'visible') {
hideLoadingScreen();
}
});
$(window).on('load', function () {
hideLoadingScreen();
});
this code is not working only on the IOS when i reload the page i need to get the loading screen but it is not showing on other non IOS it is working fine how can i fix that
I have tried a lot of thinks that are for IOS like the page hide visibility change and other thinks but still when i refresh the page it is not showing the loading screen
beforeunload
event is not supported by Mobile Safari. You can see the list of all supported events here: Handling Events Apple documentationSafari
does not support` beforeunload` in the previous link, and we can identify the browser type, if ios devices, we can usevisibilitychange
,pagehide
,pageshow
events to replacebeforeunload
event.