Auto save function when The page unload not working on safari browser

Auto save function when The page unload not working on safari browser

  

Dear all , 

I working on my project and I facing a issue relate to Safari browser. 

I have javascipt to handle save before the page unload below . All browser working fine except Safari browser. It seem save screen action do not execute . :(

window.onbeforeunload = confirmExit;
   
    function confirmExit(){        
     
        //This part saves the all VALID entries when leaving the page
       
            var elemid = $('.savebutton').attr('id');
            var elem = document.getElementById(elemid);
               
            if (typeof elem.onclick == 'function')
            {                
                elem.onclick.apply(elem);
            }        
    }

Please don't hesitate share to me if you have any hint or solution .  

Sr for my bad english 

Best regards,

Phuong

Hi Phuong,

This doesn't seem to be related to OutSystems technology... Do you always see the same behaviour? Or the confirmExit() function fails to run only if you've used your back/forward buttons? If this is the case, maybe this post (and its answer) can be useful.

Jorge Martins wrote:

Hi Phuong,

This doesn't seem to be related to OutSystems technology... Do you always see the same behaviour? Or the confirmExit() function fails to run only if you've used your back/forward buttons? If this is the case, maybe this post (and its answer) can be useful.

Hi Jorge , 

Thanks for reply , Yep I always see the same behavior, And It only encounter on safari browser. 

And I also add breakpoint in function confirmExit , I see that function execute correctly , But I don't know why the save screen action not trigger . :( 

You can see my savebutton  

Hi,

Not related to OutSystems but a quick google search shows that Safari has Back-Forward cache feature which might is affecting the window.onbeforeload event. This link might help you  - https://stackoverflow.com/questions/40938707/safari-onbeforeunload

Hi Phuong,

This can be related to the asynchronous nature of Ajax, and different behaviour of Safari regarding the onbeforeunload event. The solution I see in other places like this, this and this is to make a synchronous Ajax call.

As an alternative, you may allow the users to decide what to do?... present them with the option to continue navigating and loosing any unsaved work, or canceling in order to save their work before navigating away.