CKEditor 内容的 JavaScript 打印

标签 javascript html ckeditor

HTML:

<textarea name="Editor" class="ckeditor" id="aboutme">@Model.Content</textarea>


<button type="button" onclick="Print()">Print</button>

Javascript:

function Print() {
        printcontent($("#printDiv").html());
    }
    function printcontent(content) {

        var i = CKEDITOR.instances.editor1;

        i.editor.execCommand('print');

  }

我尝试了上面的 JavaScript 代码来打印 ckeditor 内容,但它对我不起作用。

如何在单击按钮时打印 ckeditor 内容?

最佳答案

您可以使用Print addon

This plugin activates the printing function. A standard operating system printing pop-up window will appear where you will be able to choose the printer as well as all relevant options.

然后您将能够调用print命令来打开打印对话框。

要在自定义按钮上调用命令,您可以使用:

<textarea name="Editor" class="ckeditor" id="aboutme">@Model.Content</textarea>
<button type="button" onclick="print('aboutme')">Print</button>
<script>
    function print(editorName) {
        var editor = CKEDITOR.instances[editorName];           
        editor.execCommand('print');
    }
</script>

关于CKEditor 内容的 JavaScript 打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675530/

相关文章:

php - CKEditor - CKFinder 在我上传图片后不会自动创建缩略图

javascript - CKEditor 的多个实例(在 Safari 中)

JavaScript 使用文档编写

javascript - 如何在 AngularJS 中显示数组表单字段的验证错误?

javascript - 根据来自输入的百分比值为气泡分配颜色

javascript - 如何在html表格中应用内边框

javascript - 从选择按钮添加文本到输入

javascript - 如何将 HTML5 Web Workers 与 Google Closure Tools 结合使用?

javascript - 如何使用原型(prototype)隐藏和显示信息?

javascript - 如何修复 window.CKFinder 未定义