通过jQuery捕获打印事件 [英] Capturing Print Event via jQuery

查看:341
本文介绍了通过jQuery捕获打印事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够在我的网页发送出去之前操作DOM。 Internet Explorer在名为onbeforeprint的窗口对象上有一个事件,但这是专有的,不受其他浏览器支持。是否可以通过javascript(特别是jQuery,如果可能)?

I would like to be able to manipulate the DOM just before my page is sent to be printed. Internet Explorer has an event on the window object called "onbeforeprint" but this is proprietary and isn't supported by other browsers. Is it possible to do this via javascript (jQuery in particular, if possible)?

在提出之前,我不能轻易地使用打印媒体样式表来应用更改因为我需要改变的元素有内联样式,不能用全局样式表覆盖。我需要重写这些内联样式打印的目的。如果需要,应该可以修改现有的jQuery,但是这将是一个更加耗时和风险的更改。

Before you ask, I can't easily use a print media stylesheet to apply the changes as the elements I need to change have inline styles which can't be overridden with a global stylesheet. I need to override these inline styles for print purposes. It should be possible to modify the existing jQuery if needs be, however that would be a more time-consuming and risky change.

Cheers,
Zac


Cheers, Zac

推荐答案

在CSS中的属性之后添加!important 内联样式。例如:

Adding !important after a property in your CSS will allow it to override the inline styles. For example:

<div class="test" style="color: blue;">Some Text</div>

css:

  .test {
     color: red !important;
  }

将显示为红色。

这篇关于通过jQuery捕获打印事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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