window.print去掉页头页脚

html:

<OBJECT   id="WebBrowser"   classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"   height="0"   width="0"   VIEWASTEXT></OBJECT>

 <!--startprint-->
    <div style="border:1px solid #999999; width:auto;"><img src="2010723115926746.jpg"/></div>
    <!--endprint-->

js:

<script>
/*打印*/
function doPrint() {
var bdhtml = window.document.body.innerHTML;
var sprnstr = "<!--startprint-->";
var eprnstr = "<!--endprint-->";
var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
}

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) { }
}
</script>

posted @ 2017-02-09 16:40  mysuper  阅读(4493)  评论(0编辑  收藏  举报