print()方法用于打印當前窗口的內(nèi)容瀑焦,支持部分或者整個網(wǎng)頁打印。
調(diào)用print()方法所引發(fā)的行為就像用戶單擊瀏覽器的打印按鈕梗肝。通常榛瓮,這會產(chǎn)生一個對話框,讓用戶可以取消或定制打印請求巫击。
win10下測試ie11禀晓、chrome、firefox坝锰、360粹懒、edge都可以成功去掉頁眉頁腳;
打印
.printBox {
width: 300px;
height: 300px;
border: 1px solid blue;
}
@page {
size: auto;
margin: 0mm;
}
this is content!!!
點擊按鈕打印
打印
function print_page() {
if (!!window.ActiveXObject || "ActiveXObject" in window) { //是否ie
remove_ie_header_and_footer();
}
window.print();
}
function remove_ie_header_and_footer() {
var hkey_path;
hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\InternetExplorer\\PageSetup\\";
try {
var RegWsh = new ActiveXObject("WScript.Shell");
RegWsh.RegWrite(hkey_path + "header", "");
RegWsh.RegWrite(hkey_path +"footer", "");
} catch (e) {
}
}