首页 > 解决方案 > 打印在同一而不是在弹出的新分隔页中

问题描述

我找到了一个很棒的富文本编辑器一个简单但完整的富文本编辑器

我唯一的问题是文本编辑器的打印页面在一个新的和单独的页面中弹出,但我希望它在同一页面中,那么我该如何修改它来达到那个目的?

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();
}

标签: javascriptcssprintingpopuptext-editor

解决方案


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

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

并在你的 printDoc 函数中,而不是_blank传递这个 iframe 名称inlineFrameExample

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 指定的名称。


推荐阅读