tags:

views:

408

answers:

4

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

+5  A: 

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.

Sam152
A: 

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.
Marcel Tjandraatmadja
actually i dont want to display the whole contents of the page on to the page , so i need to add some more data into the page that i want to print , that is show in the printed document but not on the web page
+1  A: 

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(); 
        }
    );
});
kkyy
+1  A: 

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!">
amartynov
can i pass a value to this page like <iframe src="to_print.html?val='<?=john?>'" name="frame1"></iframe>
Sure! Moreover, if the pages are within a single domain, you can access the document via frames[name].document property.
amartynov
thanks amartynov really appreciate the help will try it and ask if any problems appear , thanks again..;)
hey amartynov having a small problem i did this<iframe style="display:none" src="collection_Report.php?cono=<?=$control_no?>" name="frame1" ></iframe><input type="button" onclick="frames['frame1'].print(<script>frames['frame1'].style.display='block';</script>)" value="print!"> but it doesnt print
how can i hide at the begining and print without displaying the iframe
ah, instead of "display:none" you may use something like "position:absolute; top: -10px; width:0; height:0;"
amartynov
hey it didnt work but i changed the height and the border of the iframe and problem solved , thanks for the answer , ;)