TinyMCE is often used in the CMS Software. The CSS file, that is currently bound to the TinyMCE editor, needs often to be exchanged.
There are two important things:
- The current CSS file must be cleanly unloaded, otherwise their CSS rules will still affect the contents of the editor.
- If the CSS file has been just changed but its name remains the same, reloading might have no effect because of cache.
Here is the solution:
function reloadCSS()
{
// remove all previous CSS files
tinymce.activeEditor.dom.styleSheetLoader.unloadAll(tinymce.activeEditor.contentCSS);
// clean up the variable for storing the list of CSS files
tinymce.activeEditor.contentCSS = [];
// add the timestamp to the css to force loading from the server (not from cache)
let new_css = 'editor.css?t=' + Date.now();
// add new CSS files to the variable for storing the list of CSS files
tinymce.activeEditor.contentCSS.push(new_css);
// load new CSS file into the editor
tinymce.activeEditor.dom.styleSheetLoader.load(new_css);
}
I tried to do this first with hard reinitializing but it was not so effective.