javascript - 打印在同一而不是在弹出的新分隔页中
问题描述
我找到了一个很棒的富文本编辑器一个简单但完整的富文本编辑器
我唯一的问题是文本编辑器的打印页面在一个新的和单独的页面中弹出,但我希望它在同一页面中,那么我该如何修改它来达到那个目的?
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 函数中,而不是_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 指定的名称。
推荐阅读
- python - 如果原始文件中的名称有效但我的主文件中不存在,如何包含一个条件,以使匹配列给出空白?
- android - 如何解决 Android 中的“app:transformClassesWithDesugarForDebug”?
- python - 在熊猫数据框中达到某个阈值后如何返回时间索引?
- python - 定期更新带有标签的 ProgressBar
- sql-server - 执行 tsqlt 测试时 tsqlt 中的回滚错误
- python - 带有管道python的子进程
- swift - 在 Swift 应用程序中控制动态文本
- ansible - Ansible 使用 {{ item }} 和 csvfile 查找
- sql - 删除大量记录导致数据库锁定
- java - 当缓存已满时,在将新实体添加到缓存之前,休眠会从缓存中逐出哪个现有实体?