0
 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

6
  • 1
    beforeunload event is not supported by Mobile Safari. You can see the list of all supported events here: Handling Events Apple documentation
    – Jason
    Commented Aug 2, 2024 at 7:53
  • We can see a lot of reasons why Safari does not support` beforeunload` in the previous link, and we can identify the browser type, if ios devices, we can use visibilitychange, pagehide, pageshow events to replace beforeunload event.
    – Jason
    Commented Aug 2, 2024 at 8:01
  • those are not working visibilitychange, pagehide, pageshow Commented Aug 2, 2024 at 9:02
  • So we can only look for other alternatives.
    – Jason
    Commented Aug 2, 2024 at 9:34
  • 1
    To display a loading screen on iOS devices during page refreshes, implement an overlay that appears when the user navigates away. Create a full-screen overlay with CSS and trigger it using JavaScript on events like beforeunload (or unload). This visually indicates a page transition, addressing iOS limitations with beforeunload.
    – Jason
    Commented Aug 2, 2024 at 11:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.