最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML footer on bottom of all pages of HTML print out in IE - Stack Overflow

programmeradmin2浏览0评论

I am asked to get a footer on the bottom of every page of the html web page print out (not the actual page on the browser). Do you guys know any way to do it? (It should work on IE, and just IE is fine)

I tried using fixed bottom, but contents overlaps with the footer.

I tried using javascript to calculate space and give an empty div the height: was using if bottom of the footer % page height !=0, add Required gap. But the value of the bottom of the footer and required white space seems to change with change in elements type.

var printPageHeight = 1900; 
var mFooter = $("#footer-nt");
var bottomPos = mFooter.position().top + mFooter.height();


var remainingGap = (bottomPos <printPageHeight ) ? (printPageHeight -bottomPos) :       printPageHeight - (bottomPos % printPageHeight );


$("#whiteSpaceToPositionFooter").css("height", remainingGap+"px");

I tried using table, works well for all the pages, except the last one.

I tried few other margin and such tweaks but they didn't work either.

I actually want the footer to be displayed only on the bottom of the last page of the print out if that's possible.

I am asked to get a footer on the bottom of every page of the html web page print out (not the actual page on the browser). Do you guys know any way to do it? (It should work on IE, and just IE is fine)

I tried using fixed bottom, but contents overlaps with the footer.

I tried using javascript to calculate space and give an empty div the height: was using if bottom of the footer % page height !=0, add Required gap. But the value of the bottom of the footer and required white space seems to change with change in elements type.

var printPageHeight = 1900; 
var mFooter = $("#footer-nt");
var bottomPos = mFooter.position().top + mFooter.height();


var remainingGap = (bottomPos <printPageHeight ) ? (printPageHeight -bottomPos) :       printPageHeight - (bottomPos % printPageHeight );


$("#whiteSpaceToPositionFooter").css("height", remainingGap+"px");

I tried using table, works well for all the pages, except the last one.

I tried few other margin and such tweaks but they didn't work either.

I actually want the footer to be displayed only on the bottom of the last page of the print out if that's possible.

Share Improve this question edited Nov 6, 2014 at 4:01 wilson0x4d 8,7493 gold badges52 silver badges51 bronze badges asked Jul 5, 2013 at 7:05 MIWMIBMIWMIB 1,4971 gold badge14 silver badges26 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 12

I'm answering my own question just in case if anyone else needs a solution.

After a long research and intensive tries (mainly trial and errors), I used following logic to set the footer only on the bottom of the last page: -

  1. In css: @media print { position: fixed; top: 0; left: 0; z-index -1; } Ad IE displayed it on bottom of every page, and was sent to background by z-index.

  2. Still, the background of text in IE was transparent in print out, so the text was on top of footer. So, used white image of 1px by 1px in absolute top left position to act as an background of the image.

  3. Used javaScript to set the height and width of the image same as the height of the div that had content.

html:

<body>
    <div id="wrapper"> <!-- not necessary -->
        <img scr="./img/white.png" id="whiteBg" />
        <div id="content">
            <!-- content here -->
        </div>
    </div>
    <div id="footer">
    </div>
</body>

css:

@media screen {
    #whiteBg {
        display: none;
    }
}

@media print {
   #whiteBg {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1; //to send it to the background
   } 
   #wrapper {
      padding-bottom: (the size of the footer, to make footer visible on last page).
   }
   #footer {
     position: fixed;
     bottom: 0;
   }
}

jquery:

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

TO GET FOOTER ON THE BOTTOM OF EVERY PAGE, I USED: (2nd Scenario)

css:

@media print {
   #footer {
     position: fixed;
     bottom: 0;
   }
   body {
     margin: x x y x; (y should reflect the height of the footer);
}

Maybe something like this?

<link rel="stylesheet" href="print.css" type="text/css" media="print" /> /* this css file is only for printing purposes*/

body:after {
   content: "I am the footer";
}

Use the last element you have in the end of the document instead of body...

发布评论

评论列表(0)

  1. 暂无评论