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/