print()方法用于打印当前窗口的内容,支持部分或者整个网页打印。
调用print()方法所引发的行为就像用户单击浏览器的打印按钮。通常,这会产生一个对话框,让用户可以取消或定制打印请求。
win10下测试ie11, chrome, firefox, 360年,边缘都可以成功去掉页眉页脚;
& lt; !DOCTYPE html> & lt; html> & lt; head> & lt; title>打印& lt;/title> & lt;元charset=皍tf - 8”比; & lt; style> .printBox { 宽度:300 px; 身高:300 px; 边界:1 px固体蓝色; } & lt;/style> & lt; !——打印的样式——比; & lt;风格媒体=按蛴 北? @page { 大小:汽车; 保证金:0毫米; } & lt;/style> & lt;/head> & lt; body> & lt; div类=皃rintBox”比; 这是内容! ! ! & lt; br> 点击按钮打印 & lt;/div> & lt; button> 函数print_page () { 如果(! !窗口。ActiveXObject | |“ActiveXObject”窗口){//是否ie remove_ie_header_and_footer (); } window.print (); } 函数remove_ie_header_and_footer () { var hkey_path; hkey_path=" HKEY_CURRENT_USER软件\ \ \ \ \ \ \ \ Microsoft Internet Explorer PageSetup \ \”; 尝试{ var RegWsh=new ActiveXObject (“WScript.Shell”); RegWsh。RegWrite (hkey_path + "头"," "); RegWsh。RegWrite (hkey_path +“页脚”," "); }捕捉(e) { } } & lt;/script> & lt;/html>
以上这篇js客户端打印html并且去掉页眉,页脚的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。