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

2
  • do you have control over both of these web pages? Is the page you want to print yours or a foreign site. The implication is you are writing both pages I think Feb 24, 2009 at 7:28
  • actually the page im trying to print has some user information and im using traditional javascript to call that page into the main page(ajax) and in the page i need to print, should contain some additional data and should be printed using the button on the main page and should not open in new page
    – jarus
    Feb 24, 2009 at 7:40

4 Answers 4

5

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.

3

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!">
7
  • can i pass a value to this page like <iframe src="to_print.html?val='<?=john?>'" name="frame1"></iframe>
    – jarus
    Feb 24, 2009 at 7:42
  • Sure! Moreover, if the pages are within a single domain, you can access the document via frames[name].document property.
    – amartynov
    Feb 24, 2009 at 7:44
  • thanks amartynov really appreciate the help will try it and ask if any problems appear , thanks again..;)
    – jarus
    Feb 24, 2009 at 7:52
  • 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
    – jarus
    Feb 24, 2009 at 8:17
  • how can i hide at the begining and print without displaying the iframe
    – jarus
    Feb 24, 2009 at 8:17
2

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(); 
        }
    );
});
0

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.
1
  • 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
    – jarus
    Feb 24, 2009 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.