打印设置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有这个功能
搜
搜索资料,最后查询到需要添加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有这个功能
相关文章推荐
- 如何设置ie为默认浏览器
- IE9体验版让我爱你有点儿闹心,1不能发博客、2总有广告宣传页、3总问是否把IE设置为默认浏览器
- loadrunner打不开ie&ie默认浏览器设置方法
- 《WebBrowser》——— 可视区域设置,防止控件默认的自动缩小网页(可以解决加载html时字体先大后小)
- Windows 10 使用C#如何将IE设置为默认浏览器
- X-UA-Compatible IE 浏览器默认文档模式设置
- [办公应用]如何设置IE打印时的默认页边距,并设置纸张为横向(会计票据打印)
- IE9体验版让我爱你有点儿闹心,1不能发博客、2总有广告宣传页、3总问是否把IE设置为默认浏览器
- 设置锁定默认浏览器为IE
- [6月7日的脚本] 在Windows 8中将桌面版IE设置为默认浏览器 (VBScript)
- 【Win7中如何通过修改注册表将IE设置为默认浏览器】
- 设置默认訪问项目的client的浏览器版本号(IE版本号)
- 批处理IE访问多个站点,等待30秒后自动关闭IE、不需要设置IE默认浏览器
- X-UA-Compatible IE 浏览器默认文档模式设置
- 设置或解除ie,firefox,chrome为默认浏览器
- 使用IE打印,如何设置默认纸张大小,页边距等?(求救!!)
- [6月12日] 在Windows 8中将桌面版IE设置为默认浏览器 (PowerShell)
- loadrunner打不开ie&ie默认浏览器设置方法
- Win10系统如何设置默认浏览器不喜欢默认的IE