function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James JensenJames Jensen 

How to force confirmation warning before closing lightning community window

I have a Lightning Community that I would like to prevent the user from closing the window without first confirming they will lose any unsaved data.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi James,

May I suggest You Please refer the below link for reference. Let us know if it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
Ramakrishna Reddy GouniRamakrishna Reddy Gouni
document.addEventListener('beforeunload', function(){
       confirm("are you sure want to close?");
});

 
Lance Havens 13Lance Havens 13
How do I do this when a user has started to type an email message then goes to click the default X to close the page?
User-added image
Lance Havens 13Lance Havens 13
The message appears when I change data on the 'Case Details' page but not when I have started an email reply.