如何在不进行硬重新初始化的情况下即时更改 TinyMCE(版本 6)的 CSS 文件?

问题描述 投票:0回答:0

TinyMCE常用于CMS软件中。当前绑定到 TinyMCE 编辑器的 CSS 文件需要经常交换。

有两点很重要:

  • 当前的CSS文件必须干净卸载,否则它们的CSS规则仍然会影响编辑器的内容
  • 如果刚刚更改了CSS文件,但其名称保持不变,由于缓存,重新加载可能无效。

这里是解决方案:

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);
}

我尝试先通过硬重新初始化来做到这一点,但效果不佳。

css tinymce tinymce-6
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.