我找到了一个很棒的富文本编辑器 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/