如何调用onclick打印功能并忘记它

时间:2016-08-10 10:43:44

标签: javascript jquery

我写了一个打印功能,它打开一个新的标签窗口进行打印,然后该打印按钮保持活动状态,直到我不通过取消或打印关闭该窗口。在此期间,我无法在父页面上调用我的其他javascript函数。所以我的问题是,是否可以打开一个打印窗口,打印按钮再次变为非活动状态,并且窗口保持打开状态?下面是我的功能。

function g_print_div(in_div_id) {

    div_id = in_div_id || 'idprint';
    var divElements = document.getElementById(div_id).innerHTML;
    var oldPage = document.body.innerHTML;

    var printWindow = window.open();
    printWindow.document.write('<html>');

    printWindow.document.write("<link rel='stylesheet' type='text/css' href='/static/css/print.css') %]' />");

    printWindow.document.write('<body >');
    printWindow.document.write(divElements);
    printWindow.document.write('</body></html>');
    printWindow.print();

    printWindow.document.close();
    printWindow.close();
}

使用onclick='g_print_div();'函数调用,如果还有其他方法可以实现此目的,请告诉我。

1 个答案:

答案 0 :(得分:0)

我经常搜索并找到其他解决方案,我在相同的标签窗口打开了打印,而不是在其他窗口或新标签中打开。以下链接对此有帮助 http://www.aspsnippets.com/Articles/Print-DIV-content-without-opening-new-popup-window-using-JavaScript.aspx