我寫了一個基於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