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
Dnyanesh Sable 10Dnyanesh Sable 10 

I have created one Aura component and I added beforeunload event in init function so i am not able to catch beforunload evetn when i refresh the community page.

I have created one Aura component and I added beforeunload event in the init function so I am not able to catch beforunload event when I refresh the community page.
It is working in the normal salesforce page when Tab is getting close, the Browser is getting close and even refresh the page.
But when we use it in community page there is not working for a refresh. it is not a calling function.
Please can anyone help?
Thanks! 
 
doInit : function(component, event, helper) {       
        var closeCase = function(event){ 
             helper.handleCloseCase(component, event, helper);
         } 
         window.parent.addEventListener('unload', closeCase);
}
AnudeepAnudeep (Salesforce Developers) 
If your Lightning Component has an apex controller attached, and if that apex controller has code which queries the object, It could be possible that when trying to access a page in your community as an authenticated user (Partner Community User or Community User being the best examples) will not have at least read access on the object in the profile or permission set 

In order to avoid such issues, please ensure that any users accessing a component that queries the Object in the controller (even if they don't use the functions in those controllers) have at least read access to the object 


 
PapsakPPapsakP

@Dnyanesh Sable 10 - Did you get your code to work even on browser close? I have tried this within an Aura component within a Service Console app and it does not fire when closing the actual browser. Any ideas?

My code is:

Aura Controller:

doInit : function(component, event, helper) {       
        window.addEventListener('beforeunload', helper.beforeUnloadHandler.bind(helper));
}
 



Aura Helper:

beforeUnloadHandler: function(component, event,helper) {
        alert('we got it');
        console.log('DALO::before unload handler has been called.');
      }