【问题标题】:How set height for print content?如何设置打印内容的高度?
【发布时间】:2014-11-13 09:11:46
【问题描述】:

我有:

function printContent2(div_id)
 {
     var content = document.getElementById(div_id);
     var map_src = window.open("", "PRINT MAP", "width=800,height=600,top=0,left=0,toolbar=no,scrollbars=no,status=no,resizable=no");
     map_src.document.write('<html><head>');
     map_src.document.write('<link rel="stylesheet"  href="/leaflet-0.5.1/0.7.3/leaflet.css"/>');
     map_src.document.write('</head><body>');
     map_src.document.write(content.innerHTML);
     map_src.document.write('</body></html>');
     map_src.document.close();
     map_src.focus();
     map_src.print();
  }
                           .mapstyle {
                               height: 100%;
                               height: -webkit-calc(100% - 69px);
                               height: -moz-calc(100% - 69px);
                               height: calc(100% - 74px);
                               margin-left: 420px;
                           }
  div id="map" class="mapstyle"

之后

printContent2('map');

在完整列表中显示。

我需要设置高度 = 400px。

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

【问题讨论】:

    标签: javascript html printing stylesheet


    【解决方案1】:

    你可以使用这样的东西:

       map_src.document.write("<html><head><style> #"+div_id+"{height:400px !important;font-size:12px;}</style>")
    

    【讨论】:

    • 你有没有用你的 div 的 id 替换 yourId。
    【解决方案2】:

    尝试添加Div wrap

    function printContent2(div_id)
     {
         var content = document.getElementById(div_id);
         var map_src = window.open("", "PRINT MAP", "width=800,height=600,top=0,left=0,toolbar=no,scrollbars=no,status=no,resizable=no");
         map_src.document.write('<html><head>');
         //map_src.document.write('<link rel="stylesheet"  href="/leaflet-0.5.1/0.7.3/leaflet.css"/>'); ** Remove this line
         map_src.document.write("</head><body><div style='height:400px;border:1px solid blue;'>");
         map_src.document.write(content.innerHTML);
         map_src.document.write('</div></body></html>');
         map_src.document.close();
         map_src.focus();
         map_src.print();
      }
    

    更新答案:我看过你的代码。您的代码似乎有问题。只需在行下方删除或评论,它对我有用。

     map_src.document.write('<link rel="stylesheet"  href="/leaflet-0.5.1/0.7.3/leaflet.css"/>'); // Remove this Line.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 2014-02-28
      相关资源
      最近更新 更多