I've looked through the docs, so forgive me if this is written down somewhere. Is it possible to do something like window.onunload for a Lightning component? window.onunload (or .onbeforeunload) both work for the user refreshing the page or going to a different site, but I can't get an event to fire if they navigate to a different component within a Lightning app (I want to track time spent using certain components).
-
1FYI, I stumbled across this post when trying to capture when a user attempts to leave a lightning component by clicking a different tab in Lightning Experience - the senior program architect from salesforce here confirmed with sfdc product management that this is currently not possible, but may be in the near future– Brian MansfieldCommented Jun 6, 2017 at 14:30
Add a comment
|
1 Answer
Why don't you call a function in the button you're using to close the component?
If you're using a close button or a navigation button that ends the component you can call a function on that button.
-
I considered that, but I'd also like to capture when a user leaves the page or closes the browser window (to be able to track time spent on component as well as prompt a user if they have unsaved edits). Commented Oct 28, 2016 at 13:32
-
Well, to track de time you can just create a time script. Commented Oct 28, 2016 at 17:31
-
the time* And for the unsaved edits you could call the function on the button Commented Oct 28, 2016 at 17:31