• 在网页中用JavaScript控制DIV进行预览打印


    function doPrint(){
        var article;
        var css;
        var strAdBegin="";
        var strAdEnd="";
        var strTmp;
        var str="<html>
    <meta http-equiv='content-type' content='text/html; charset=gb2312'>";
        css="<style>"+"td,.f12{font-size:12px}";
        css +="body{font-family:宋体;border:1px #6f6f6f solid;}";
        css +=".f24 {font-size:24px;}";
        css +=".f14 {font-size:14px;}";
        css +=".content_text{97%;margin-left:3%;}";
        css +=".title14 {font-size:14px;line-height:130%}";
        css +=".l17 {line-height:170%;}";
        css +=".x14 {font-size:14px;line-height:130%}";
        css +="a.zwy:link,a.zwy:active,a.zwy:visited,a.zwy:hover{text-decoration:none;color: #311bad;}";
        css +="a.htt:link,a.htt:active,a.htt:visited{text-decoration:none;color: #7b4109;}";
        css +="</style>";
    
        str +=  css;
        str +="<link href='/css/com_article.css' rel='stylesheet' type='text/css' />";
        str +=  '<meta http-equiv="content-type" content="text/html; charset=gb2312">';
        str +=  '<title>'+document.title+'</title>';
        str +=  "<body bgcolor=#ffffff topmargin=5 leftmargin=5 marginheight=5 marginwidth=5 >";
        str +=  "<center><table width=650  border=0 cellpadding=0 cellspacing=0 ><tr>";
        str +=  "<td align=left valign=bottom style='padding-top:12px;'>View</td>";
        str +=  "<td align=right valign=bottom style='padding-top:12px;'><a href='javascript:window.print()'><strong>Print</strong></a> <a href='javascript:history.back()'><strong>Back</strong></a></td></tr></table>";
        str +=  "<table  style='650px;border:#8EDDE6 1px solid;'><tr><td>";
        str +=document.getElementById('print_nav').innerHTML+"</td></tr><tr><td>";
        article=document.getElementById('divContext').innerHTML;
        var nv  =  document.getElementById('div_multipagenav');
        if (nv!=null)
        {    
           var nav =document.getElementById('div_multipagenav').innerHTML;
           article=article.replace(nav,"");
        }
        var hzh=document.getElementById('TomHZH');
        if (hzh !=null)
        {
          var oldhzh=document.getElementById('TomHZH').innerHTML;
          article=article.replace(oldhzh,"");
        }
        if(article.indexOf(strAdBegin)!=-1)
        {
          str +=article.substr(0,article.indexOf(strAdBegin));
          strTmp=article.substr(article.indexOf(strAdEnd)+strAdEnd.length, article.length);
        }
        else
        {
            strTmp=article
        }
        str +=strTmp
        str +=  "</td></tr></table></center><div style='height:25px;'></div>";
        str +=  "</body></html>";
        document.write(str);
        window.print();
        document.close();
    }

        str +=document.getElementById('print_nav').innerHTML+"</td></tr><tr><td>";
        article=document.getElementById('divContext').innerHTML;  //这是获取要打印内容的地方
        var nv  =  document.getElementById('div_multipagenav');

        这三个ID必须有!DIV标记的ID

    HTML页面内的使用方法:

    Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />、
    <title>Print</title>
    <script type="text/javascript" language="javascript" src="doPrint.js"></script>
    </head>
    <body>
    <form id="form1">
       <div id="print_nav"></div>
       <div id="divContext">
          <img src="images/edm_01.jpg" alt="" />
       </div>
       <div id="div_multipagenav"></div>
       <input type="button" value="print" onclick="doPrint();" />
    </form>
    </body>
    </html>
  • 相关阅读:
    计算机图形学学习方法和相关书籍,做游戏,GIS,虚拟现实,三维引擎的都能够看看.
    HDU 1248 寒冰王座(全然背包:入门题)
    android widget 开发实例 : 桌面便签程序的实现具体解释和源代码 (上)
    Oracle varchar 字段排序问题
    Response.AddHeader使用实例
    Unity 3D 文件导入出错
    Sencha app build 出现 missing name after . operator 问题
    TFS(Team Foundation Server)介绍和入门
    较具体的介绍JNI
    Struts2学习笔记1
  • 原文地址:https://www.cnblogs.com/guide2it/p/3471256.html
Copyright © 2020-2023  润新知