<!DOCTYPE html>
<html>
<head>
<title>print</title>
<meta charset="utf-8">
<style media="print">
@page {
size: auto;
margin: 0mm;
}
</style>
</head>
<body>
<div style="width:300px; height:300px;border: 1px solid blue;">
<label>label</label>
<button>button</button>
</div>
<button onclick='print_page()'>print</button>
</body>
<script type="text/javascript">
function print_page() {
if (!!window.ActiveXObject || "ActiveXObject" in window) {
remove_ie_header_and_footer();
}
window.print();
};
function remove_ie_header_and_footer() {
var hkey_root, hkey_path, hkey_key;
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>
</html>
html调用浏览器打印,去掉页眉页脚
最新推荐文章于 2022-12-16 15:04:51 发布
本文介绍了一个简单的网页打印布局示例,并针对Internet Explorer浏览器进行了特定的头部和页脚设置去除,以确保打印效果的一致性和美观性。示例中使用了HTML, CSS和JavaScript来实现页面内容的展示及打印功能。
1万+

被折叠的 条评论
为什么被折叠?



