gpt4 book ai didi

javascript - 使用 window.open 中的按钮打印

转载 作者:行者123 更新时间:2023-11-27 23:05:29 25 4
gpt4 key购买 nike

我有以下按钮可以打开一个新窗口

<a href="javascript:void(0);" class="btn btn-lg green" onclick="PrintElem('#sample_editable_1', 'Fault Recording')"><i class="fa fa-file-text-o" aria-hidden="true" style="padding-right: 5px;"></i>Run Report</a>

在我的 js 文件中,我有创建窗口的函数:-

function PrintElem(elem, h1)
{
Popup($(elem).html(), h1);
}

function Popup(data, h1)
{
var mywindow = window.open('', 'my div', 'height=768,width=1024');
mywindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
mywindow.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
mywindow.document.write('<html><head><title></title>');
mywindow.document.write('<link rel="stylesheet" href="'+base_url+'/css/print1.css'+'" type="text/css" />');
mywindow.document.write('<link rel="stylesheet" href="'+base_url+'/assets/global/plugins/font-awesome/css/font-awesome.min.css'+'" type="text/css" />');
mywindow.document.write('<script src="'+base_url+'js/custom.js'+'" type="text/javascript"></script>');
mywindow.document.write('</head><body>');
mywindow.document.write('<h1 class="pdfTitleDv" >'+h1+'</h1>');
mywindow.document.write($('#window_print').html());
mywindow.document.write('<table border="0" cellpadding="0" cellspacing="0" class="table table-bordered table-striped table-condensed flip-content table-hover datatableDv " id="sample_editable_1">');
mywindow.document.write(data);
mywindow.document.write('</table>');
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
return true;
}

function print(){
window.print();
}

我在创建的新窗口中有以下按钮我有一个按钮我想打印窗口中的表格。请看下面的 HTML:-

<div class="btn-group pull-right btm-btn">
<a href="javascript:void(0);" class="btn btn-lg green" onclick="print()"><i class="fa fa-print" aria-hidden="true" style="padding-right: 5px;"></i>Print</a>
</div>

我想打印新窗口中的表格。谁能帮我实现这个目标??任何帮助将不胜感激。

最佳答案

在你的打印函数中添加window.print(),它会强制打印。

关于javascript - 使用 window.open 中的按钮打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58761682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com