IE8及以下版本可以调用WebBrowser.ExecWB(7,1) 函数弹出浏览器的打印预览对话框,采用该函数的好处是 用户可以在打印预览对话框中 调整页边距、页眉、页脚;
下面贴出的是设置页边距、页眉、页脚的JS代码
//取得页面打印设置的原参数数据 function PageSetup_temp(){ try { var Wsh=new ActiveXObject("WScript.Shell"); HKEY_Key="header"; //取得页眉默认值 head = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key); HKEY_Key="footer"; //取得页脚默认值 foot = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key); HKEY_Key="margin_bottom"; //取得下页边距 bottom = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key); HKEY_Key="margin_left"; //取得左页边距 left = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key); HKEY_Key="margin_right"; //取得右页边距 right = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key); HKEY_Key="margin_top"; //取得上页边距 top = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key); } catch(e){ //alert("不允许ActiveX控件"); } } //设置网页打印的页眉页脚和页边距,注册表里的单位是英寸,打印设置中是毫米,1英寸=25.4毫米 function PageSetup_Null(){ try { var Wsh=new ActiveXObject("WScript.Shell"); HKEY_Key="header"; //设置页眉(为空) Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); HKEY_Key="footer"; //设置页脚(为空) Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); HKEY_Key="margin_bottom"; //设置下页边距(0) Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.6"); HKEY_Key="margin_left"; //设置左页边距(0) Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.3"); HKEY_Key="margin_right"; //设置右页边距(0) Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.3"); HKEY_Key="margin_top"; //设置上页边距(8) Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.6"); } catch(e){ //alert("不允许ActiveX控件"); } } //设置网页打印的页眉页脚和页边距为默认值 function PageSetup_Default(){ try { var Wsh=new ActiveXObject("WScript.Shell"); HKEY_Key="header"; HKEY_Key="header"; //还原页眉 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,head); HKEY_Key="footer"; //还原页脚 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,foot); HKEY_Key="margin_bottom"; //还原下页边距 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,bottom); HKEY_Key="margin_left"; //还原左页边距 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,left); HKEY_Key="margin_right"; //还原右页边距 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,right); HKEY_Key="margin_top"; //还原上页边距 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,top); } catch(e){ //alert("不允许ActiveX控件"); } }
使用该函数,会弹出
通过网页修改activex安全设置,添加信任站点,禁用该弹出窗口提示,代码如下:
function activeXControl(){ try{ var WshShell=new ActiveXObject("WScript.Shell"); //添加信任站点() WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\",""); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\:Range","127.0.0.1"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\http","2","REG_DWORD"); //修改IE ActiveX安全设置: 1本地Intranet区域 WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1\\1001","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1\\1004","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1\\1200","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1\\1201","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1\\1405","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1\\2201","0","REG_DWORD"); //修改IE ActiveX安全设置:2受信任的站点区域 WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1001","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1004","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1200","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1201","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1405","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\2201","0","REG_DWORD"); //修改IE ActiveX安全设置:3Internet区域 WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1001","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1004","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1200","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1201","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1405","0","REG_DWORD"); WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\2201","0","REG_DWORD"); //禁用Winxp弹出窗口阻止程序 WshShell.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\New Windows\\PopupMgr","no"); }catch(e){ //alert("不允许ActiveX控件"); } }
3.问题