您的位置:首页 > 其它

打印设置IE打,浏览器默认是启用缩小字体填充

2013-10-31 09:57 375 查看
IE浏览器默认是打勾(选中),所以每次页面打印的时候都会缩小字体。每次打印要手动去修改,这样比较麻烦,用户使用不方便。



搜索资料,最后查询到需要添加document.execCommand('print', false, null);

代码如下:

    document.execCommand('print', false, null);

    print(document);

如果把document.execCommand('print', false, null);放在print()下面,还会缩小字体,起不到作用,还是要放在print()的上面,才能起到作用。

添加document.execCommand('print', false, null);以后FireFox的问题如下:

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.execCommand]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://test.test010.com/myclasses/examterm/ff8080812ebe6577012ec1cebc2f0012/?placeValuesBefore :: submintPrints :: line 124" data: no]

查看说是firefox的问题。为了能让firefox也能打印,把代码修改如下:

if($.browser.msie) { //IE

    document.execCommand('print', false, null);

}

print(document);

 
 
js控制页边距
 

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(){
alert('设置开始了');

 try{

    alert('121设置开始了');

    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,"1.05");   

    HKEY_Key="margin_left";   

 //设置左页边距(0)   

    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"5");   

    HKEY_Key="margin_right";   

 //设置右页边距(0)   

    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"5");   

    HKEY_Key="margin_top";   

 //设置上页边距(8)   

    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.2");

    alert('设置结束了');  

 }catch(e){   

      alert("不允许ActiveX控件");   

 }  
 
}
 
虽然可以控制页边距,但是需要安装
http://www.meadroid.com/scriptx
页面会弹出各种错误,不可取。记录于此处,是想知道js有这个功能 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: