日期:2014-05-17 浏览次数:21298 次
<script language="JavaScript" type="text/JavaScript">
var hkey_root,hkey_path,hkey_key;
hkey_root="HKEY_CURRENT_USER";
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
function pagesetup_null(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="margin_left" //定义左边距
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.25") //0.25为边距,根据实际修改
hkey_key="margin_right" //定义右边距
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.25")
}catch(e){
}
}
</script>
------解决方案--------------------
我们公司是用ReYoPrint,给你个调用的例子
<OBJECT ID="ReYoPrint" CLASSID="CLSID:5C230622-45E5-4e3c-893C-3BFDDC4DB5E4" codebase="../ReYoPrint.cab" height="0" width="0"></OBJECT>
<script>
ReYoPrint.MarginLeft=4; //设置左边边距
ReYoPrint.MarginRight=2; //设置右边边距
ReYoPrint.MarginTop=4; //设置上边边距
ReYoPrint.MarginBottom=2; //设置下边边距
ReYoPrint.CopyCount=1; //打印份数
ReYoPrint.PageHeader=""; //页眉
ReYoPrint.PageFooter=""; //页脚
ReYoPrint.IsLandScape=0; //把页面设置为横向1
//ReYoPrint.ContentURL="http://www.interdrp.com/print.html";
</script>
<div class="only_print_view">
<input type="button" id="btnPrint" value="打印预览" onClick="ReYoPrint.PrintPreview()">
<input type="button" id="btnPrint" value="打印文件" onClick="ReYoPrint.Print()">
<input type="button" id="btnPrint" value="直接打印" onClick="ReYoPrint.PrintDirect()">
------解决方案--------------------
还能去除页眉页脚
<HTML><HEAD>
<script language="VBScript">
dim hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\Software\Microsoft\Internet Explorer\PageSetup"
'//设置网页打印的页眉页脚为空
function pagesetup_null()
on error resume next
Set RegWsh = CreateObject("WScript.Shell")
hkey_key="\header"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
hkey_key="\footer"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
end function
'//设置网页打印的页眉页脚为默认值
function pagesetup_default()
on error resume next
Set RegWsh = CreateObject("WScript.Shell")
hkey_key="\header"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"
hkey_key="\footer"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d"
end function
</script>
</HEAD>
<BODY onload="pagesetup_null()" onbeforeunload="pagesetup_default()">
</BODY></HTML>
------解决方案--------------------
上面是用onload和onunload事件来执行这两个操作,还可以用按钮操作
<HTML><HEAD>
<script language="JavaScript">
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
//设置网页打印的页眉页脚为空
function pagesetup_null(){
try{
var