
增強功能列印 DIV 內容
在各種 Web 開發場景中,您可能會遇到列印特定 DIV 元素內容的需求。為了實現這一目標,有幾種方法可用。在本文中,我們將深入研究一種在不同瀏覽器(特別是 Chrome)之間提供增強功能和相容性的方法。
解
提供的函數 PrintElem() ,提供了列印內容的綜合方法DIV:
function PrintElem(elem) {
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title></head>');
mywindow.document.write('<body>');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}說明
透過使用此函數,您可以輕鬆列印任何具有頁面標題等附加功能的 DIV 元素的內容,確保相容性並為您的用戶提供流暢的列印體驗。
以上是如何增強瀏覽器相容性列印特定DIV的內容?的詳細內容。更多資訊請關注PHP中文網其他相關文章!