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()) {
window.location.reload();
}
Arguments
None.
Return value
Type boolean
Returns true
when:
- the Item or Activity has no changes
- not in the Item editor or Activity editor views
Returns false
when:
- the Item or Activity has unsaved changes.
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.