Managing Page Unload With the Items API

This article describes the configuration options that can be set on initialization and details how the Items API handles page unload events and how the client can override these.
The Items API needs to handle the case where a page unload may fire, while there are unsaved responses. For this purpose, the Items API will add a custom event handler "beforeunload" to the window object that presents the user with a warning that their unsaved responses will be lost if they proceed.

Developers can attach their own "beforeunload" event through the "eventsOptions.customUnload" when initializing Items API. This custom event will be triggered before the default behaviour gets fired.

If the "customUnload" returns a truthy value like a string/true, the browser's default onbeforeunload popup will show up.

Important: if the onbeforeunload event is overridden after LearnosityItems.init() has been executed, the Items API will lose its ability to detect onbeforeunload events and will not perform any of its default behaviour.

var itemsApp = LearnosityItems.init(activity, {
readyListener: function () {},                    
errorListener: function () {},
customUnload: function () {                    
    console.log('beforeunload event has been triggered');
    return true;
Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.