Results 1 to 7 of 7

Thread: Printing a timestamp on a call to print function

  1. #1
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Printing a timestamp on a call to print function

    Got a small problem that I am at a loss to figure out how to get it working.

    I got a perfectly good call to print function that elminates some surrounding headers/footers to make my data printer friendly....works great.

    Code:
    <script language="JavaScript">
    var gAutoPrint = true; // Tells whether to automatically call the print function
    function printSpecial()
    {
    if (document.getElementById != null)
    {
    var html = '<HTML>\n<HEAD>\n';
    
    if (document.getElementsByTagName != null)
    {
    var headTags = document.getElementsByTagName("head");
    if (headTags.length > 0)
    html += headTags[0].innerHTML;
    }
    
    html += '\n</HE>\n<BODY>\n';
    
    var printReadyElem = document.getElementById("BotTable");
    
    if (printReadyElem != null)
    {
    html += printReadyElem.innerHTML;
    }
    else
    {
    alert("Could not find the printReady function");
    return;
    }
    
    html += '\n</BO>\n</HT>';
    
    var printWin = window.open("","printSpecial");
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();
    if (gAutoPrint)
    printWin.print();
    }
    else
    {
    alert("The print ready feature is only available if you are using an browser.  Please update your browswer.");
    }
    }
    </script>

    Except now I need to somehow get a timestamping function to display on the printed page. I cannot have it display on the webpage but can display on the secondary (print preview) page. Is there any way to incorporate a time/date function within my provided javascript to put a small timestamp on the printed page?

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Use JS to display the current date/time. A full explanation can be found here
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by BLiZZaRD View Post
    Use JS to display the current date/time. A full explanation can be found here
    Yea, well thats fine for displaying it but I do not want to display it on the website....only the final printed page. Attempts to incorporate it into my currect js have proven futile.

    You may see it here at the bottom on the "print this page" button.
    http://www.saunas.com/Steam%20Shower...s/default.aspx

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    You could use the <link rel type=print option in the head to make it so they print a page different than what they are actually seeing, you can then put the time code on this page.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by BLiZZaRD View Post
    You could use the <link rel type=print option in the head to make it so they print a page different than what they are actually seeing, you can then put the time code on this page.
    I think you mean media, the type should be text/css for all stylesheet links:

    Code:
    <link rel="stylesheet" href="styles.css" media="screen" type="text/css">
    <link rel="stylesheet" href="print.css" media="print" type="text/css">
    Once you have separate print and screen stylesheets, you can use them to display only those portions of the document that you wish to for printing, and to format as desired for that purpose. The styles for the live (screen) page would go in the other stylesheet. You could have a division:

    HTML Code:
    <div id="printTime">&nbsp;</div>
    In your screen stylesheet, its display property could be none, in the print stylesheet, it could be block. When you go to print, just before the actual print command, do:

    Code:
    document.getElementById('printTime').firstChild.nodeValue=new Date().toLocaleString();
    It will place the current date and time in the division, visible only to the printer and print preview.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    While I did not go exactly in that direction you suggested, I did figure out a pretty good solution based on your ideas. Thank you both very much!

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    I think you mean media, the type should be text/css for all stylesheet links:
    Yes that is what I meant... it has been a very long week and the Scotch isn't helping.. yet...
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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
  •