javascript - 在同一个页面中打印,而不是在弹出的新单独页面中打印

标签 javascript css printing popup text-editor

我找到了一个很棒的富文本编辑器 A simple but complete rich text editor

我遇到的唯一问题是文本编辑器的打印页面在一个新的单独页面中弹出,但我希望它在同一页面中,所以我如何修改它才能达到这个目的?

function printDoc() {
  if (!validateMode()) { return; }
  var oPrntWin = window.open("","_blank","width=450,height=470,left=400,top=100,menubar=yes,toolbar=no,location=no,scrollbars=yes");
  oPrntWin.document.open();
  oPrntWin.document.write("<!doctype html><html><head><title>Print<\/title><\/head><body onload=\"print();\">" + oDoc.innerHTML + "<\/body><\/html>");
  oPrntWin.document.close();
}

最佳答案

在您的 HTML 中有一个 iframe,如下所示

 <iframe id="inlineFrameExample" name="inlineFrameExample" title="Inline Frame Example" width="0" height="0">
  </iframe>

并在您的 printDoc 函数中,传递此 iframe 名称 inlineFrameExample 而不是 _blank

var oPrntWin = window.open("", "inlineFrameExample", "width=450,height=470,left=400,top=100,menubar=yes,toolbar=no,location=no,scrollbars=yes");

解释

var window = window.open(url, windowname, [windowFeatures]);

窗口名称

DOMString 指定要加载指定资源的浏览上下文(窗口、<iframe> 或选项卡)的名称;如果该名称未指示现有上下文,则会创建一个新窗口并为其指定由 windowName 指定的名称。

关于javascript - 在同一个页面中打印,而不是在弹出的新单独页面中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53218447/

相关文章:

java - 我的程序可以运行,但在应该打印时却无法打印

javascript - 谷歌浏览器 Kiosk 模式打印延迟

javascript - JavaScript 的替换功能不起作用

javascript - 使用 CarrierWave 和 Rails 设置 Froala 所见即所得编辑器

javascript - 选择选项的自定义属性并从 Angular 5 中的 AbstractControl 访问它?

css - 阻止 body 进入固定菜单

css - Bootstrap 按钮固定宽度

javascript - 单独接受参数与数组

javascript - 更改 "Choose File"按钮并继续显示文件名

java - 如何生成用户范围内的随机数?