Do modern browsers support onbeforeprint / onafterprint HTML events?

后端 未结 3 560
既然无缘
既然无缘 2021-01-24 01:58

I am trying to update content of my page for printing. I want to have labels (spans) for each input element (textboxes, lists, etc.) to prevent text-cutoff when printing. I want

3条回答
  •  攒了一身酷
    2021-01-24 02:30

    The MDN page on onbeforeprint is marked as updated last Nov 14, 2013, and it says “no” for Chrome, Opera, and Safari, “(Yes)” for IE, and “6.0” for Firefox. This is consistent with the results of checking with the current Chrome (version 34) and the last Windows version (5.1.7) of Safari. No event is triggered on them, and in developer tools, no onbeforeprint listener is shown under “Event Listeners” in developer tools when onbeforeprint attribute is used.

    There is a WebKit bug report from 2008 about lack of support to beforeprint and afterprint events, and there’s a suggested patch but also issues with it, and it does not seem to be making progress.

    So the answer is “No.”

    Cf. onbeforeprint and onafterprint is not working in Chrome and IE?

    As regards to the possible followup question “What should I use instead, then?”, it should be posted as a new question, with sufficient details (including code) to describe the original problem – in particular, what would be the part that you cannot do by using a print stylesheet.

提交回复
热议问题