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!