检查用户何时选择使用 javascript 打印 [英] Check for when a user has selected to print using javascript
问题描述
当用户在 Firefox 或 Internet Explorer 等浏览器上选择文件 > 打印",或点击运行以下 javascript 的链接时
When a user chooses "File > Print" on a browser such as Firefox or Internet Explorer, or clicks on a link that runs the below javascript
window.print();
有没有办法有条件地检查这种模式并禁用一些javascript.
Is there a way to conditionally check for this mode and disable SOME javascript.
我正在尝试这样做,因为我有一个插件,它为圆形边框添加了自己的自定义标记,即使在打印特定的样式表中,我也无法覆盖这些样式,我不希望在打印时出现边框页面.
I am trying to do this because I have a plugin that adds in its own custom markup for rounded borders and even in a print specific stylesheet I can not override the styling for these, I dont want the borders to appear when printing out the page.
与插件无关,通过用于创建选项卡式用户界面的 javascript 完成了样式更改,我已经完成了打印特定的 CSS 以覆盖样式,并且在我使用时它工作正常Firefox Web 开发人员工具栏 > CSS > 按媒体类型显示 CSS > 打印.. 但是当我打印出来它不起作用时,javascript 接管并更改样式.. 如果我完全禁用 javascript 那么打印显然工作正常再次.
Unrelated to the plugin there are style changes done via javascript that is used to create a tabbed user interface and I have done print specific CSS to override the styling and it works fine when I use the Firefox web developer toolbar > CSS > Display CSS by Media type > Print.. but when I print it out it doesn't work, the javascript takes over and changes the styling.. if I disable javascript completely then the printing obviously works fine again.
谢谢
推荐答案
您可以:
window.old_print=window.print
window.print=function() {
alert('doing things');
window.old_print();
}
但这只会从页面 javascript 内部捕获对 print()
的调用.
but this will only catch calls to print()
from inside the page javascript.
您是否尝试将 !important
放在特定于打印的样式表上?
Did you try putting !important
on print-specific stylesheet?
这篇关于检查用户何时选择使用 javascript 打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!