Forum Discussion
JulioPalacios
3 years agoCommunity Member
Is there anyway to execute javascript when a learning module is closed?
I'm creating a self-assessment tool and I'm using javascript to send variables to a Google sheet. I'd like a way to track some information on learners who are not completing the assessment tool. Spe...
MathNotermans-9
3 years agoCommunity Member
There is. The window beforeunload event just does that.
https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
There are some differences how and when it is called. Eg. you donot want it to trigger when a user changes to another tab in the browser, this event occurs whenever a user navigates away from a page and even on a reload. So principally this is called when the user closes his browser... but you have to figure out an approach to prevent calling it ( or adding conditions you check ) when its not needed... reload and changing to a tab i guess.