我找到了一个很棒的富文本编辑器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函数中,而不是
_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]);
windowName
一个DOMString,指定要将指定资源加载到其中的浏览上下文的名称(窗口,或选项卡);如果名称不表示现有上下文,则将创建一个新窗口,并为其指定由windowName指定的名称。