js 设置网页打印的页眉页脚和页边距

Bensonhai 2013-07-23 02:35:55
本人是用js写,代码如下:
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");
HKEY_Key = "margin_left";
//设置左页边距(0)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
HKEY_Key = "margin_right";
//设置右页边距(0)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
HKEY_Key = "margin_top";
//设置上页边距(8)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "8");
} catch(e) {
alert("不允许ActiveX控件");
}
}
ActiveXObject("WScript.Shell");这个对象无效,网上的方法我都试过了,都无效
...全文
405 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bensonhai 2013-07-23
  • 打赏
  • 举报
回复
var HKEY_Root,HKEY_Path,HKEY_Key; HKEY_Root="HKEY_CURRENT_USER"; HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; var head,foot,top,bottom,left,right; //取得页面打印设置的原参数数据 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控件"); } }
Bensonhai 2013-07-23
  • 打赏
  • 举报
回复
引用 4 楼 fzfei2 的回复:
[quote=引用 3 楼 amy1314250 的回复:] 在IE下运行,也开放了,但是还是不行
如果 开放安全限制了就不会提示 这个对象无效 了 你的 HKEY_Root , HKEY_Path 有设置过值?? [/quote]设置过了
fzfei2 2013-07-23
  • 打赏
  • 举报
回复
引用 3 楼 amy1314250 的回复:
在IE下运行,也开放了,但是还是不行
如果 开放安全限制了就不会提示 这个对象无效 了 你的 HKEY_Root , HKEY_Path 有设置过值??
Bensonhai 2013-07-23
  • 打赏
  • 举报
回复
在IE下运行,也开放了,但是还是不行
ztszhq 2013-07-23
  • 打赏
  • 举报
回复
web打印自定义 是个比较头疼的事。 网上一些 打印控件 也是基于ActiveX 所以 浏览器兼容性很是问题
fzfei2 2013-07-23
  • 打赏
  • 举报
回复
ActiveXObject ,只在IE下运行,并开放安全限制

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧