SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast dandare's Avatar
    Join Date
    Mar 2005
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Print

    hi All

    Im printing the contents of a browser - no problems there, but what I need is to tack on the same printout an extra line of text that is not available when the page is loaded. Reloading the page is not an option im afraid. Is there anyway i can do this??

    Thanks

    Dan

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you add it to the page but use a stylesheet to hide it and then use a print stylesheet to show it when the page is printed?

    (As far as I know, there is no cross-browser way to do this with JavaScript.)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Enthusiast dandare's Avatar
    Join Date
    Mar 2005
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the sugestion Kravvitz - the problem I have is that the text will consist of an indentification number that has not been generated at the time the page is rendered. This will only be generated when the print button is pushed.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You would have to update the page with the new content prior to calling the print function. Just set up a function that does both the generation of the identification number followed by the call to print the page.

    You can always use CSS to define that the div containing the identification number is not to display on the screen but is to be printed. Here is some of the code you could use:

    <style>
    .print {display:none}
    @media print {
    .print {display:block;}
    }
    </style>
    <script type="text/javascript">
    function genNumberPrint() {
    document.getElementById('num').innerHTML = generatedNumber;
    window.print();
    }
    </script>
    <div class="noprint" id="num"></div>
    <div onclick="genNumberPrint()">Click here to print</div>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •