利用隐藏帧打印url的方法比较
点击次数:31 次 发布日期:2008-11-21 22:25:25 作者:源代码网
|
源代码网推荐源代码网整理以下点击一个按钮或者链接需要打印另外一个页面,即打印一个url。
源代码网整理以下页面增加一个link 元素这样的方法比较简单,其实还可以在页面做个隐藏帧的方法来实行,不过比上面那种方法要笨一些
源代码网整理以下下面看一个利用隐藏帧打印url的示例:
源代码网整理以下function printURL (url) { if (window.print && window.frames && window.frames.printerIframe) { var html = ""; html += "<html>"; html += "<body onload="parent.printFrame(window.frames.urlToPrint);">"; html += "<iframe name="urlToPrint" src="" + url + ""></iframe>"; html += "</body></html>"; var ifd = window.frames.printerIframe.document; ifd.open(); ifd.write(html); ifd.close(); } } function printFrame (frame) { if (frame.print) { frame.focus(); window.print(); //使用页面的打印 } }
源代码网整理以下再看一个隐藏帧利用插件的打印 function printURL (url) { if (window.print && window.frames && window.frames.printerIframe) { var html = ""; html += "<html>"; html += "<body onload="parent.printFrame(window.frames.urlToPrint);">"; html +="<object style="display:none" id="oPrintCtl" classid="clsid:CA03A5A8-9890-49BE-BA4A-8C524EB06441" codebase="eprintdemo.cab#Version=3,0,0,9" VIEWASTEXT></object>"; html += "<iframe name="urlToPrint" src="" + url + ""></iframe>"; html += "</body></html>"; var ifd = window.frames.printerIframe.document; ifd.open(); ifd.write(html); ifd.close(); } } function printFrame (frame) { if (frame.print) { frame.focus(); window.frames.printerIframe.document.oPrintCtl.Preview(); // window.frames.printerIframe.document.oPrintCtl.Print(); // window.frames.printerIframe.document.oPrintCtl.Print(true); } 利用插件的预览,打印等功能实现。 源代码网供稿. |