打印时,光标现在同时显示和打印。而且即使在编辑器外部单击也无法摆脱它-打印时它仍然可见!
它易于复制,只需文件/打印即可。
谢谢!
标记
发布于 2020-11-14 00:54:06
最近,我正在开发一个网页应用程序,我们用HTML语言创建标签,用TinyMCE编辑它们,然后打印它们。我也遇到了同样的问题。在他们为此发布补丁之前,您可以尝试以下工作。
在你的TinyMCE初始化中,使用一个BeforeExecCommand回调将插入符号放到一个隐藏的div中,在我的例子中,我把它放在第一个div中:
tinymce.init({...,
  init_instance_callback: function (editor) {
    editor.on('BeforeExecCommand', function (e) {
      if (e.command === 'mcePrint') {
        editor.selection.setCursorLocation(editor.dom.select('div')[0]);
      }
    });
  }
});然后在HTML的开头创建一个div,类似于...
<div style="position: absolute; left: -10000px, top: -10000px; width: 0px; height: 0px; overflow: hidden;"></div>当你点击‘打印’时,回调将触发并将光标放到这个隐藏的div中,从而将其从视图中移除,打印的内容看起来应该如您所愿。
我们可以通过将插入符号放回打印前的位置来改进这里的用户体验。我不会详细介绍,但是如果你想这样做,你可以把插入符号的位置保存在一个变量中,然后在TinyMCE初始化中使用另一个回调函数:
tinymce.init({...,
  init_instance_callback: function (editor) {
    editor.on('BeforeExecCommand', function (e) {
      if (e.command === 'mcePrint') {
        // Before the print executes, do this...
        // Your code to save the current caret position goes here
        // Move caret to hidden div
        editor.selection.setCursorLocation(editor.dom.select('div')[0]);
      }
    });
  }
  init_instance_callback: function (editor) {
    editor.on('ExecCommand', function (e) {
      if (e.command === 'mcePrint') {
        // After the print executes, do this...
        // Your code to move the caret back to its original position goes here
      }
    });
  }
});发布于 2020-11-17 21:07:26
我只想让每个人都知道这是TinyMCE中的一个bug。一种快速的解决方法是将以下样式添加到content css
@media print {
    .mce-visual-caret {
        display: none;
    }
}下面是一个有效的https://fiddle.tiny.cloud/baaaab示例
https://stackoverflow.com/questions/64581482
复制相似问题