我写了一个基于JavaScript的网页打印功能。它从页面上的隐藏div中提取HTML,将其呈现到新窗口并触发打印对话框。屏幕阅读器和JavaScript打印功能
该选项通过button
与onclick="printTheThing()"
事件可用。我知道,例如屏幕阅读器有JavaScript的一些警告。 我想知道是否/有多少人,如盲人或视力受损我阻止使用此功能。
的实施将打开一个新的浏览器窗口,并追加到它的文档:
function printTheThing() {
var dispSettings = "toolbar=yes,location=no,directories=yes,menubar=yes,"
+ "scrollbars=yes,width=550,height=400",
html = $('#theDivToPrint').html(),
printWindow = window.open("", "", dispSettings),
doc = printWindow.document;
doc.open();
try {
doc.write('<html><head>');
doc.write('<title>' + title + '</title>');
doc.write('</head><body>');
doc.write(html);
doc.write('</body></html>');
} finally {
doc.close();
}
printWindow.focus();
printWindow.print();
}
更新:这是按钮看起来像什么:
<button type="button" onclick="printTheThing()">Print the thing!</button>
另外,我使用的CSS用图像替换按钮。我已经用Firefox插件“Fangs”测试了这个按钮。它表明屏幕阅读器将完美地读出原始按钮文本。但Fangs不提供任何交互性,所以我不能用它来测试打印。
如何尝试自己? https://chrome.google.com/webstore/detail/kgejglhpjiefppelpmljglcjbhoiplfn – 2012-04-20 12:57:02
那样:-)添加它作为答案? – chiccodoro 2012-04-20 13:03:04