2

I'm trying to ask for confirmation before leaving a page in case the user wants to save his data.

This is the code I'm using on Chrome/Firefox

window.onbeforeunload = function(e)
{

    if(CKEDITOR.instances.webEditor.checkDirty() || CKEDITOR.instances.printEditor.checkDirty())
    {
        $scope.setDirty(true);
    }

    if(!$scope.uploadingPost && $scope.isDirty)
    {
        return "Are you sure you want to leave?";
    }

};

Which doesn't work on Safari.

I tried using this on Safari, without results.

window.addEventListener('pagehide', function (event) 
{
    window.event.cancelBubble = true;
    if(CKEDITOR.instances.webEditor.checkDirty() || CKEDITOR.instances.printEditor.checkDirty())
    {
        $scope.setDirty(true);
    }

    if(!$scope.uploadingPost && $scope.isDirty)
    {
        return "Are you sure you want to leave?";
    }
});

Is there any way to display a confirmation pop-up before leaving the page on Safari, I know that WordPress does it, but how?

Thank you!

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
troyz
  • 1,345
  • 2
  • 11
  • 19
  • Possible duplicate of [window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera?](http://stackoverflow.com/questions/14645011/window-onbeforeunload-and-window-onunload-is-not-working-in-firefox-safari-o) – Karol Klepacki Aug 17 '16 at 12:01
  • Don't think this is a duplicate. I'm having the same issue. Basically, pagehide is no longer fired in Safari for IOS although I believe, as there own documentation states, it was supported at one time - https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5. Good luck in getting anything from apple support channels - I've seen the question asked multiple times with no reply – no1spirite Sep 14 '16 at 07:29

0 Answers0