Babu Babu - 1 year ago 144
Ajax Question

How do I print different page using javascript/jQuery/ajax?

With following code it's showing the print dialog box and print the page successfully but how do i print a different page after click on this same button ? Different page name is : letterprint.php

<div class="below_movie_left" id="printableArea">
My printing contents

<input type="button" class="submit_button" onclick="printDiv('printableArea')" value="Print" style="float:right;" />

function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;

document.body.innerHTML = printContents;


document.body.innerHTML = originalContents;

Is this possible with javascript / jQuery / Ajax method ? how ?

Answer Source

If you already have the page you want to print, put that page in an hidden iframe and print the content of iframe

<iframe src="letterprint.php" name="frame"></iframe>

<input type="button" onclick="frames['frame'].print()" value="printletter">