Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    201
    Thanks
    51
    Thanked 0 Times in 0 Posts

    Printing one web page from another web page

    Hi All,

    I have created a "print safe" version of a web page that I would like to have printed when the user clicks a button on another web page. I know about the print() method but is it possible to have this printing a different web page (not the page that is currently loaded in the browser)? If not, how could this be done through javascript?

    Thanks,

    Ken

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Quote Originally Posted by MaDmiX View Post
    Hi All,

    I have created a "print safe" version of a web page that I would like to have printed when the user clicks a button on another web page. I know about the print() method but is it possible to have this printing a different web page (not the page that is currently loaded in the browser)? If not, how could this be done through javascript?

    Thanks,

    Ken
    Not possible. You cannot redirect or redefine the browser's print button. That would be a security problem. You could perhaps load the page to be printed in an <iframe>.

    (Untried)

    Code:
    <iframe src="page2print.htm" name="ifr" height="0" width="0" frameborder="0"> </iframe>
    <input type="button" value="print" onClick="frames['ifr'].print()">
    Quizmaster: The two numerals in a fraction are the numerator and the what?
    Contestant: Decimator
    Last edited by Philip M; 09-06-2012 at 05:34 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    MaDmiX (09-06-2012)

  • #3
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    201
    Thanks
    51
    Thanked 0 Times in 0 Posts
    Thank you Philip,

    Originally it was printing the webpage and not the iFrame but I added this script to redirect the focus and it works great now.

    Code:
    <head>
    <script type="text/javascript">
    function printFrame(myFrame)
    {
      myFrame.focus();
      myFrame.print();
    }
    </script>
    </head>
    <body>
    <iframe src="tqc-print-preview.php?tblProgramInfoID=<?php echo $row_rstProgramInfo['tblProgramInfoID']; ?>" name="ifr" height="0" width="0" frameborder="0"> </iframe>
    <input type="button" value="Print Report" onClick="printFrame(ifr)">
    </body>


  •  

    Posting Permissions

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