Skip to main content

Autosave

Plugin alias: autosave

editor42.init({
plugins: 'autosave'
});

Periodically saves editor content to localStorage as a draft and can restore it later. Prompts the user before leaving the page if there are unsaved changes. Drafts expire after a configurable retention period.

Options

OptionTypeDefaultDescription
autosave_ask_before_unloadbooleantrueShow browser warning when navigating away with unsaved changes.
autosave_prefixstring'editor42-autosave-{path}{query}{hash}-{id}-'localStorage key prefix; supports {path}, {query}, {hash}, {id} placeholders.
autosave_restore_when_emptybooleanfalseAuto-restore draft on init if editor is empty.
autosave_intervalstring'30s'Interval between automatic draft saves, e.g. '30s', '5m'.
autosave_retentionstring'20m'How long a draft remains valid before it is discarded.

Toolbar buttons

NameTypeDescription
restoredraftButtonRestore last draft; disabled when no draft exists.
NameDescription
restoredraftRestore last draft.

Events

EventDescription
StoreDraftFired when a draft is saved.
RestoreDraftFired when a draft is restored.
RemoveDraftFired when a draft is removed.

API

MethodDescription
hasDraft()Returns boolean indicating whether a draft exists.
storeDraft()Saves current content as a draft.
restoreDraft()Restores draft into the editor.
removeDraft(fire?)Removes the draft. Fires RemoveDraft unless fire is false.
isEmpty(html?)Checks if the editor content (or provided HTML) is empty.