JavaScript – HTML页脚底部的HTML页面在IE中打印出来

前端之家收集整理的这篇文章主要介绍了JavaScript – HTML页脚底部的HTML页面在IE中打印出来前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我被要求在html网页的每一页的底部找到一个页脚,打印出来(而不是浏览器上的实际页面).你们知道有什么办法吗? (它应该在IE上工作,只是IE是好的)

我尝试使用固定底部,但内容与页脚重叠.

我尝试使用JavaScript来计算空间并给出一个空的div的高度:正在使用如果底部的页脚%页面高度!= 0,添加所需的差距.但是,底部的页脚和所需的空白区域的值似乎随元素类型的变化而变化.

  1. var printPageHeight = 1900;
  2. var mFooter = $("#footer-nt");
  3. var bottomPos = mFooter.position().top + mFooter.height();
  4.  
  5.  
  6. var remainingGap = (bottomPos <printPageHeight ) ? (printPageHeight -bottomPos) : printPageHeight - (bottomPos % printPageHeight );
  7.  
  8.  
  9. $("#whiteSpaceToPositionFooter").css("height",remainingGap+"px");

我尝试使用表,除了最后一个以外,对所有页面都很好.

我尝试了几个其他的边距和这样的调整,但他们也没有工作.

我实际上希望页脚只能在打印输出的最后一页的底部显示,如果可能的话.

解决方法

我正在回答我自己的问题,以防其他人需要解决方案.

经过长时间的研究和密集的尝试(主要是试验和错误),我使用以下逻辑仅在最后一页的底部设置页脚:

>在css中:@media print {position:fixed;顶部:0;左:0; z-index -1; }广告IE显示在每个页面底部,并被z-index发送到背景.
>然而,IE中的文本背景在打印输出中是透明的,因此文本位于页脚之上.所以,在绝对的左上角位置使用1px×1px的白色图像作为图像的背景.
>使用javaScript设置图像的高度和宽度与具有内容的div的高度相同.

HTML:

  1. <body>
  2. <div id="wrapper"> <!-- not necessary -->
  3. <img scr="./img/white.png" id="whiteBg" />
  4. <div id="content">
  5. <!-- content here -->
  6. </div>
  7. </div>
  8. <div id="footer">
  9. </div>
  10. </body>

CSS:

  1. @media screen {
  2. #whiteBg {
  3. display: none;
  4. }
  5. }
  6.  
  7. @media print {
  8. #whiteBg {
  9. display: block;
  10. position: absolute;
  11. top: 0;
  12. left: 0;
  13. z-index: -1; //to send it to the background
  14. }
  15. #wrapper {
  16. padding-bottom: (the size of the footer,to make footer visible on last page).
  17. }
  18. #footer {
  19. position: fixed;
  20. bottom: 0;
  21. }
  22. }

jQuery的:

  1. @('#whiteBg').height( $('#content')).height() );

在每个页面底部都可以看到,我使用了:(第二种情况)

CSS:

  1. @media print {
  2. #footer {
  3. position: fixed;
  4. bottom: 0;
  5. }
  6. body {
  7. margin: x x y x; (y should reflect the height of the footer);
  8. }

猜你在找的JavaScript相关文章