Author API Methods
safeToUnload()
Checks if the current Item or Activity being edited has any unsaved changes or not. That is, whether it is safe to unload the Author API instance, or reload the page.
You would want to use this method so that you can ensure that any unsaved changes will not be lost when navigating to another page, for example.
To override the safeToUnload
state, see the setSafeToUnload()
method.
Note When creating a new Item, it behaves as if all changes are saved. However, when creating a new Activity, it behaves as if it has unsaved changes, to allow saving of an empty Activity.
Examples
// Reload the page if there are no unsaved changes
if (authorApp.safeToUnload('item_edit')) {
window.location.reload();
}
Arguments
-
componentName string
The name of the view to check.
Possible values
-
"activity_edit"
Version added: v2025.2.LTS
-
"item_edit"
Version added: v2025.2.LTS
-
"item_settings"
Version added: v2025.2.LTS
-
"mathgen"
Version added: v2025.2.LTS
-
"widget_edit"
Version added: v2025.2.LTS
-
Return value
Type boolean
Returns true
when:
- the view corresponding to the argument has no changes
- the view corresponding to the argument is currently not loaded, for example when calling this with
item_edit
while editing an Activity
Returns false
when:
- the view corresponding to the argument has unsaved changes.
Caveats
As of the latest Developer version and v2025.2.LTS, this method requires the componentName
argument to be specified.
Related articles
- The
disable_onbeforeunload
initialization option, which controls whether Author API will ignore the default browser behavior for showing an unsaved changes warning. - The
setSafeToUnload()
method, which updates the internal status of the specified view to override its status indicating whether it has any unsaved changes.