【问题标题】:Styling the preview in CKEditor with CSS使用 CSS 为 CKEditor 中的预览设置样式
【发布时间】:2012-09-06 21:41:44
【问题描述】:

我已将 CKEditor 集成到我的网站 CMS 中。预览按钮有效,但我无法让它使用样式表 (CSS)。我已经编辑了 preview.html 位于:

网站/ckeditor/插件/预览/

但它似乎没有听我环绕从所见即所得编辑器中提取内容的代码的任何 html。

据我了解这段代码:

<script>

var doc = document;
doc.open();
doc.write( window.opener._cke_htmlToLoad );
doc.close();

delete window.opener._cke_htmlToLoad;

</script>

拉入编辑器中的任何内容,因此我应该能够环绕该 html 以包含可用于每个页面的元素?以及样式表的链接?

有人做过吗?有可能吗?

【问题讨论】:

    标签: javascript html ckeditor wysiwyg


    【解决方案1】:

    “window.opener._cke_htmlToLoad”似乎是一个字符串(包含一个完整的 html 文档)。

    要获取

    的innerHtml,你可以使用这个正则表达式:
    var doc = window.opener._cke_htmlToLoad; // is string
    var innerBody = ( doc.replace(/((?:.(?!<\s*body[^>]*>))+.<\s*body[^>]*>)|(<\s*\/\s*body\s*\>.+)/g,'') );
    document.getElementById('insertIntoMe').innerHTML = innerBody;
    

    根据我的测试,这似乎只适用于 Firefox。但是 Chrome 和 Internet Explorer 直接显示窗口文档,不允许任何更改。那么也许其他人可以提供更好的解决方案?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多