Add a browser prompt when users attempt to navigate away from pages with unsaved TinyMCE content.
Prevents accidental data loss when users reload, close tabs, or navigate away after editing documentation, tickets, or other rich text fields.
Something like:
tinymce.init({
selector: '#mytextarea',
setup: function (editor) {
editor.on('init', function () {
window.onbeforeunload = function () {
if (editor.isDirty()) {
return "You have unsaved changes. Are you sure you want to leave?";
}
};
});
}
});