最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript Event Handler for Print - Stack Overflow

programmeradmin8浏览0评论

I am trying to alter style at print-time:

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?

I am trying to alter style at print-time:

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?

Share Improve this question edited Feb 11, 2009 at 1:23 user13276 asked Feb 11, 2009 at 0:44 user13276user13276 4,8835 gold badges23 silver badges16 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 7

Different Style Sheets

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" />

One Style Sheet

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;
    }
}

In IE there are the nonstandard window.onBeforePrint() and window.onAfterPrint() event listeners. There isn't a non-IE way to do it that I know of, however.

What kinds of changes are you trying to make? It's possible that your problem could be solved by specifying different rules for your print stylesheet.

Firefox 6 now supports beforeprint and afterprint

https://developer.mozilla/en/Printing#Detecting_print_requests

We also found that you can do a print-only style with the following:

<style type="text/css">
@media print {
    div
    {
        overflow:visible;
    }    
}
</style>

IE has onbeforeprint and onafterprint

发布评论

评论列表(0)

  1. 暂无评论