网站首页 > 知识剖析 正文
一、去掉页眉页脚的打印。虽然后面的JS函数中,也有类似的功能,经实践检验似乎不起作用。下面的代码是有效的,并且可以调整上、下边距。
<style type="text/css" id="style1">
@page { margin-top:80px; margin-bottom:30px;}
</style>
二、显示在页面上的“打印”按钮。
<input type="button" name="button_print" value="打印" onclick="javascript:printHTML()">
三、JS代码。
<script type="text/javascript">
/**打印页面*/
function printHTML(_this) {
// 获取当前页的html代码
var bdhtml = window.document.body.innerHTML;
// 通过id获取需要打印的页面
var printHtml = document.getElementById('form-div').innerHTML;
// 需要打印的页面
window.document.body.innerHTML = printHtml;
if (!!window.ActiveXObject || "ActiveXObject" in window) { //是否ie
remove_ie_header_and_footer();
}
//调用打印
window.print();
// 还原界面
window.document.body.innerHTML = bdhtml;
window.location.reload();
}
//去掉页眉、页脚
function remove_ie_header_and_footer() {
var hkey_path;
hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
try {
var RegWsh = new ActiveXObject("WScript.Shell");
RegWsh.RegWrite(hkey_path + "header", "");
RegWsh.RegWrite(hkey_path + "footer", "");
} catch (e) {
}
}
</script>
猜你喜欢
- 2024-12-23 轻量级开源wiki系统介绍 轻量开源论坛
- 2024-12-23 为了强推Edge浏览器,微软在Win11搞起了小动作
- 2024-12-23 分享windows好用的几个插件 w10插件
- 2024-12-23 windows浅尝NW.js windows浅色主题壁纸
- 2024-12-23 windows系统如何搭建网站? windows2016搭建网站
- 2024-12-23 推荐50个超实用的 Chrome 扩展,建议收藏
- 2024-12-23 Mozilla找到了让Firefox成为Windows 11默认浏览器的新方法
- 2024-12-23 HTML 也能开发桌面软件之 NW.js 中的 App 应用程序类
- 2024-12-23 把HTML网页下载为单文件,可离线访问
- 2024-12-23 站长在线HTML5精讲:HTML的相关概念详解
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)