现代浏览器是否支持onbeforeprint / onafterprint HTML事件? [英] Do modern browsers support onbeforeprint / onafterprint HTML events?

查看:361
本文介绍了现代浏览器是否支持onbeforeprint / onafterprint HTML事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更新我的网页内容以供列印。我想为每个输入元素(文本框,列表等)设置标签(跨度),以防止在打印时进行文本截断。我想在打印之前确保所有这些标签反映了最新的用户输入的值从他们各自的输入字段。

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 to make sure before printing that all these labels reflect the most up-to-date user entered values from their respective input fields.

我的第一个想法是只是把每个文本框后面的标签,并在页面渲染时使用相同的值绑定它,然后根据CSS媒体属性隐藏/显示输入或标签。但是,我还需要为每个输入元素提供 onchange 处理程序,以便在每次更改其值时更新其相应的标签。

My first idea was to just put a label after each textbox, and bind it with the same value on page render, and then hide/show the input or the label based on CSS media attribute. But then I also need to have onchange handlers for every input element to update its respective label every time its value is changed.

我的下一个想法是使用 onbeforeprint 和一些jQuery在一个地方用当前值更新标签。清洁,集中,更简洁的代码。

My next thought was to use onbeforeprint and some jQuery to update the labels on the fly with the current values all in one spot. Cleaner, centralized, more concise code.

但是据我所知, onbeforeprint onafterprint 仅在IE和Firefox中受支持。 ...但是,每一篇文章或帖子我可以找到关于浏览器支持这两个功能的谈话是从一个很好的4或5年,或甚至更多的前!

But as far as I can tell, onbeforeprint and onafterprint are only supported in IE and Firefox. ... BUT ... every article or post I can find that talks about browser support for these two functions is from a good 4 or 5 years, or even more ago!

因此,我想知道,Chrome和Safari在过去5年中的任何时候都添加了对这两个函数的支持?

So I'm wondering, have Chrome and Safari added support for these two functions at any point in the past 5 years?

推荐答案

onbeforeprint 上的MDN页面在2013年11月14日被标记为已更新,并对Chrome,Opera和Safari显示为否 表示IE,6.0表示Firefox。这与使用当前Chrome(版本34)和最后一个Windows版本(5.1.7)的Safari进行检查的结果一致。他们没有触发任何事件,而在开发人员工具中, onbeforeprint 时, onbeforeprint 侦听器不会显示在开发人员工具的事件侦听器 $ c>属性。

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.

有一个 2008年WebKit错误报告,说明缺少对 beforeprint afterprint 事件的支持,有一个建议的补丁,但也有问题,它似乎没有取得进展。

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.

因此答案是否。

Cf。 onbeforeprint和onafterprint在Chrome和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.

这篇关于现代浏览器是否支持onbeforeprint / onafterprint HTML事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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