[英]Open iframe content in new window
我想在新窗口中打开 iframe 而不是打印,我试过但无法让它工作
编辑只是想打开新窗口并查看结构,因为我的页面有动态数据并想要打印样式。
$('.btn-prnt').on("click", function(e){
var divElements = $(".contentWrap").html();
var oldPage = document.body.innerHTML;
var iframe = $('<iframe class="hidden" id="printer"></iframe>').appendTo('body');
var printer = $('#printer');
printer.contents().find('body').append("<html><head><title>Print Title</title><style></style></head><body><table width='670'><tr><td colspan='2'>" + divElements + "</td></tr></table></body>");
printer.get(0).contentWindow.print();
printer.remove();
});
您的问题的通用解决方案包括以下两个步骤:
要打开一个新窗口,您可以使用window.open
。
要将HTML
内容写入新窗口的文档,请获取它并使用document.write
。
代码:
$('.btn-prnt').on("click", function(e) {
var
/* Create a new window. */
newWin = window.open(),
/* The html you want to write in the new window. */
html = "<html>...</html>";
/* Get the window's document and write the html content. */
newWin.document.write(html);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.