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

Print in the same not in a pop-up new seperated page

我找到了一个很棒的富文本编辑器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, [window特征]);

window姓名

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

指定的名称