/** * 兼容IE8的列印頁面區域區域 * $('#printBody')為頁面上0寬0高的div * @param printhtml 要列印的區域的innerHTML */ function printOrder(printhtml) { //清空之前列印插入的html $('#printBody').html(''); //新建一個iframe var iframe = document.createElement('iframe'); iframe.id = 'printf'; //iframe寬高設定,因為IE8下iframe不能設為0寬,這里寫1 iframe.style.width = '1'; iframe.style.height = '1'; iframe.style.border = "none"; //將iframe插入到printBody里 document.getElementById("printBody").appendChild(iframe); setTimeout(function () { if (document.all) { //IE下,在iframe里呼叫列印 iframe.contentDocument.write("<script type='text/javascript'> window.onload=function(){ document.execCommand('print'); } </script>" + printhtml); iframe.contentDocument.close(); } else { //其它瀏覽器直接呼叫 iframe.contentDocument.write(printhtml); iframe.contentDocument.close(); iframe.contentWindow.focus(); iframe.contentWindow.print(); } }, 100) };
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/174084.html
標籤:其他
上一篇:jQuery 高亮顯示
下一篇:postman使用
