用于打印的 Javascript 事件处理程序 [英] Javascript Event Handler for Print

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

问题描述

我正在尝试在打印时更改样式:

I am trying to alter style at print-time:

javascript 中是否存在可以在调用 file>>print 时侦听的事件?它是什么?另外 - 打印完成时是否有处理程序?它是什么?

Is there an event in javascript that you can listen for for when file>>print is called? What is it? Also - is there a handler for when printing is finished? What is it?

或者如果有更好的方法可以通过其他方式(例如样式表)做到这一点,您会怎么做?

or if there is a better way to do this with some other means, such as style sheets, how do you do that?

推荐答案

不同的样式表

您可以指定不同的样式表进行打印.

You can specify a different stylesheet for printing.

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

一个样式表

正如 kodecraft 所提到的,您也可以使用@media 块将样式放入同一个文件中.

As kodecraft mentioned, you can also put the styles into the same file by using the @media block.

@media print {
    div.box {
        width:100px;
    }
}

@media screen {
    div.box {
        width:400px;
    }
}

这篇关于用于打印的 Javascript 事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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