回调函数后javascript打印对话? [英] Callback function after javascript print dialogue?

查看:139
本文介绍了回调函数后javascript打印对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个页面上有很多文本和一个表格上的例子。



我想让用户能够只打印表,打印此表'javascript链接,但我仍然希望通过正常的浏览器打印方法打印页面的其余部分。



因此,开始我有一个打印。 css样式表如下:

 < link type =text / css =stylesheethref = print.cssmedia =print> 

在print.css中有一个'.noPrint'设置为display:none。



在我看来,解决方案是使用'tempNoPrint'类在div中封装不是表格的内容,并且在点击打印此表格时添加了javascript add 'noPrint'给所有的'tempNoPrint',因此隐藏他们在打印机版本。



这很好,我相信会工作很好。

但是,如何在所有的'tempNoPrint'div 之后删除'noPrint'类,只打印表格就完成了?是否有从打印对话框发送的javascript回调?我可以使用一个计时器,但似乎是非常不可靠的。

解决方案

看起来我过于复杂的问题! >

我在页面上包含了所有的内容,我不想使用'noPrintCustom'类打印按钮div,然后我调用这个函数:

  var printCustom = function(){

$('noPrintCustom')。addClass('noPrint');
window.print();
$('。noPrintCustom')。removeClass('noPrint');
}

感谢所有帮助!


So I have a page with a lot of text and a table on it for example.

I want users to be able to print just the table with a 'print this table' javascript link, but I still want the rest of the page to be printable via the normal browser print method.

So to start with I have a print.css stylesheet included as below:

<link type="text/css" rel="stylesheet" href="style/print.css" media="print">

In print.css I have a class '.noPrint' set to display: none.

It seems to me that the solution is to wrap the content that is not a table in divs with a 'tempNoPrint' class, and on clicking the 'print this table' have javascript add 'noPrint' to all of the divs with 'tempNoPrint' thus hiding them in the printer version.

That's fine and I'm sure would work well.

However, how do I go about removing the 'noPrint' class from all the 'tempNoPrint' divs after the printing of just the table is done? Is there a javascript callback sent from the print dialogue? I could use a timer but it seems that would be very unreliable.

解决方案

It seems I was overcomplicating the issue!

I wrapped all the content on the page that I didn't want to print with the button divs with a 'noPrintCustom' class, then I call this function:

var printCustom = function() {

    $('.noPrintCustom').addClass('noPrint');
    window.print();
    $('.noPrintCustom').removeClass('noPrint');
}

Thanks to all that helped!

这篇关于回调函数后javascript打印对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆