jarus
jarus

Reputation:

how to print another page from the current page?

i need to print a different page from the current page , that is to describe my problem more precisely .. i need to put the print button in one page but need to print a different page , also need to send a value to the second page which is to be printed. If somebody could help me will be very much thankfull

Upvotes: 4

Views: 9810

Answers (4)

amartynov
amartynov

Reputation: 4175

Just put the page to print into an invisible iframe:

<iframe src="to_print.html" name="frame1"></iframe>
<input type="button" onclick="frames['frame1'].print()" value="print!">

Upvotes: 3

kkyy
kkyy

Reputation: 12450

You could load the page to be printed into an (possibly hidden) iframe and then call the window.print function on that frame. Using jquery it would be something like this (not tested):

$('#printButton').click(function(evt) {
    evt.preventDefault();
    $('body').append('<iframe src="document_to_be_printed.php?param=value" id="printIFrame" name="printIFrame"></iframe>');
    $('#printIFrame').bind('load', 
        function() { 
            window.frames['printIFrame'].focus(); 
            window.frames['printIFrame'].print(); 
        }
    );
});

Upvotes: 2

Marcel
Marcel

Reputation: 6290

Off the top of my head I could do as follows:

  1. Get the print button to send a or POST/GET with the details to the page you want to print.
  2. Load those details onto the page.
  3. Have a JavaScript trigger the print event once you load the page you want to print.
  4. Send the user back to the original page.

Upvotes: 0

Sam Becker
Sam Becker

Reputation: 19636

Have the link go the the page you need printing with some information in the query string. Then place javascript in the onLoad event for the body instructing the page to print.

Upvotes: 5

Related Questions