JavaScript 打印网页内容

打印整个页面

window.print();

隐藏网页中有些不打印的区域,需设置以下格式

<style type="text/css" media=print>
.noprint{display:none}
</style>

再引用 .noprint 类选择器 设置class="noprint"

打印网页局部内容

function onPrint(block) {

var value = document.all.block.innerHTML;
var printdetail = window.open("","printDetail","");
printdetail.document.open();
printdetail.document.write("<HTML><head></head><BODY οnlοad='window.print()'>");
printdetail.document.write("<PRE>");
printdetail.document.write(value);
printdetail.document.write("</PRE>");
printdetail.document.close("</BODY></HTML>");
}

<div id="block">打印内容</div>

<a href="javascript:onPrint();">打印按钮</a>

去掉页面页眉页脚

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="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
}catch(e){}
}

再设置Internet 属性 -->> 安全 -->>选择下面一排第一个Internet-->>点击自定义,将ActiveX 控件和插件都设置为提示 应用

打印之后,就得到干净的页面了

更多详情,请参考http://blog.csdn.net/woaitiyu/article/details/3161248

当需要打印页面的时候,往往需要设置页面的字体格式,这里我简单介绍一下字体

word中汉字对应大小:
42磅对应初号、36磅对应小初、26磅对应一号、24磅对应小一号、22磅对应二号、18磅对应小二号、16磅对应三号、15磅对应小三号、14磅对应四号、12磅对应小四号、10.5磅对应五号、9磅对应小五号、7.5磅对应六号、6.5磅对应小六号、5.5磅对应七号、5磅对应八号
磅:pt
单位, pt pc px mm cm in em

字体格式 例如 <span style="font-family:黑体;font-size:16pt">打印标题</span>。。。。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值