在JavaScript中诱捕CTRL + P并调用自定义函数进行打印 [英] Trapping CTRL + P in javascript and calling a custom function for printing

查看:268
本文介绍了在JavaScript中诱捕CTRL + P并调用自定义函数进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我可以在其中弹出帐单信息.此弹出窗口是DIV,而不是新窗口. 在该弹出窗口中有两个div,一个是按住打印"和关闭"按钮 另一种是持有iframe.

这是因为,当单击打印按钮时,将打印iframe的内容,这样就不会打印打印"和关闭"按钮.就像...

<div id='popupandcenterscreen'>
<div>... print and close buttons</div>
<div><iframe></div>
</div>

因此,它是一个清单,其中单击时,每个条目都有一个帐单链接.显示弹出窗口,其中加载了iframe以显示帐单信息.

当用户单击打印"按钮时,我们仅打印iframe的文档内容.

但是当用户使用CTRL + P时,包括backgroung父窗口和该弹出div在内的整个窗口将被打印.

我以为是在弹出窗口打开时捕获ctrl + p并只打印iframe内容.

怎么可能?

我认为更好的解决方案是通过CSS中的@media规则控制渲染,或者根据媒体类型添加不同的样式表.然后,您可以使用display之类的CSS属性来隐藏某些要打印的元素,甚至为它们指定不同的大小和位置.

I have a webpage where i show billing information in a pop. This popup is a DIV and not an new window. In that popup there are two div's one is to hold the print and close button and the other is to hold an iframe.

Then reason is when the print button is clicked the content of the iframe is printed so that the print and close buttons will not get printed. it is like...

<div id='popupandcenterscreen'>
<div>... print and close buttons</div>
<div><iframe></div>
</div>

So, it is a listing where each entry has a bill link when clicked the popup is displayed in which an iframe is loaded to display the billing information.

When user clicks the print button we are printing only the document content of the iframe.

BUT WHEN THE USER USED CTRL + P the total window including the backgroung parent window and this popup div gets printed.

what i thought was to trap ctrl+p when the popup is open and to print only the iframe content.

How could that be possible?

解决方案

I think a better solution would be to control rendering through @media rules in your CSS, or include different stylesheets based on the media type. You can then use CSS properties like display to hide some elements for printing, or even give them different sizes and positions.

这篇关于在JavaScript中诱捕CTRL + P并调用自定义函数进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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