网页打印(不使用插件的情况下)

来源:互联网 发布:万销淘宝店铺装修工具 编辑:程序博客网 时间:2024/05/21 11:25
//剔除不需要打印的部分        function Contrarypreview() {            bdhtml = document.body.innerHTML;            sprnstr = "<!--startprint-->";            eprnstr = "<!--endprint-->";            var tophtml = bdhtml.substr(0, bdhtml.indexOf(sprnstr));            var bothtml = prnhtml.substring(bdhtml.indexOf(eprnstr)+15);            document.body.innerHTML = tophtml + bothtml;            document.execCommand("print");        }
function preview() {            bdhtml = window.document.body.innerHTML;            sprnstr = "<!--startprint-->";            eprnstr = "<!--endprint-->";            prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);            prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));            window.document.body.innerHTML = prnhtml;            window.print();        }```已测试

function print4() {
var headhtml = document.getElementById(“head”).innerHTML;
//alert(headhtml);
var headstr = “” + headhtml + ““;
var footstr = ““;
var printData = document.getElementById(“dvData”).innerHTML; //获得 div 里的所有 html 数据
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr + printData + footstr;
//window.print();
document.execCommand(“print”);
//document.body.innerHTML = oldstr;
return false;
}

function print2() {
document.execCommand(“print”);
}
function print3() {
window.print();
}

----------

function print5() {
(‘#Div1’).attr(“style”,”display:none;”);  
            document.execCommand(“print”);
(‘#Div1’).attr(“style”, “display:block;”);
}
“`

阅读全文
0 0