Submit a request
Submit a request

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 set a custom event handler for window.onbeforeunload that presents the user with a warning that their unsaved responses will be lost if they proceed.

The message displayed can be changed through the onbeforeunload attribute of the labelBundle as explained in Internationalization.

Items API needs to override this behaviour and provide a custom onbeforeunload event handler, it must do so before calling LearnosityApp.init(). Items API will wrap any existing event handler for onbeforeunload and execute it instead of executing the default behaviour when the event gets triggered.

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.

// Custom unload
window.onbeforeunload = function () {
    return "Are you sure you want to quit?";

var itemsApp = LearnosityItems.init(activity);
Was this article helpful?
2 out of 4 found this helpful

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