应用scriptx的factory实现打印
昨晚应用IE自带的控件实现了打印,有一些东西老不是怎样如意。今天,用factory再次实现WEB打印。
1、插入CSS
- <style media="print">
- .noprint{display:none;}
- .pagenext{page-break-after: always;}
- .bgcolor {
- background-color: #CCCCCC;
- }
- </style>
2、插入JS
- <script defer>
- function setInstallStyles(fOK) {
- document.getElementById("installFailure").runtimeStyle.display = fOK ? "none" : "block";
- document.getElementById("Main").runtimeStyle.display = fOK ? "block" : "none";
- }
- function okInstall() {
- setInstallStyles(true);
- }
- function noInstall() {
- setInstallStyles(false);
- }
- function viewinit() {
- if (!factory.object) {
- noInstall();
- return
- } else {
- okInstall();
- factory.printing.header = ""
- factory.printing.footer = ""
- factory.printing.portrait = false
- factory.printing.leftMargin = 0.75
- factory.printing.topMargin = 0.75
- factory.printing.rightMargin = 0.75
- factory.printing.bottomMargin = 0.75
- // enable control buttons
- var templateSupported = factory.printing.IsTemplateSupported();
- var controls = idControls.all.tags("input");
- for ( i = 0; i < controls.length; i++ ) {
- controls[i].disabled = false;
- if ( templateSupported && controls[i].className == "ie55" )
- controls[i].style.display = "inline";
- }
- }
- }
- </script>
3、在页面加载的时候初始化插件
- <body onload="viewinit()">
4、插入插件
- <object id="factory" style="display:none" viewastext classid="clsid:1663ED61-23EB-11D2-B92F-008048FDD814" codebase="http://www.meadroid.com/scriptx/smsx.cab#Version=6,3,435,20">
- </object>
5、不打印部分
- <center class="noprint" id=idControls>
- <p>
- <input type=button class="button" value="打印本页" onclick="factory.printing.Print(false)">
- <input type=button class="button" value="页面设置" onclick="factory.printing.PageSetup()">
- <input type=button class="button" value="打印预览" onclick="factory.printing.Preview()">
- </p>
- </center>
6、插入没有安装插件显示代码
- <div id="installFailure" class="noprint" style="display:none">
- <h2>It appears ScriptX is unavailable or has failed to install.</h2>
- <p><b>Has the Infobar appeared?</b></p>
- <p>If you are using Internet Explorer 6 or later on Windows XP SP2 or later then the Explorer Information bar may appear while trying to install ScriptX, it looks like this:</p>
- <p style="padding: 4px"><img src="../images/infobar.png"></p>
- <p>If the bar has appeared, follow the instructions: click on the bar and then select <i>Install ActiveX Control...</i></p>
- <p><b>Are you an administrator?</b></p>
- <p>ScriptX is code that requires you have administrator rights on your machine in order to install it successfully.</p>
- <p>If you are not an administrator, please contact your administrator and ask them to install ScriptX for you.</p>
- </div>
Koctr said,
四月 16, 2008 at 1:18 下午
document.getElementById(“Main”)中的Main对应什么?
已加你的MSN
hey idiot buy mp3s only here! said,
九月 4, 2009 at 9:50 下午
hey idiot buy mp3s only here!…
Very usefull. Thanks! hey idiot buy mp3s only here!…