How to print another page using javascript / jQuery / ajax?

With the following code, it shows the print dialog and prints the page successfully, but how can I print another page after clicking on the same button? Different page name: letterprint.php

<div class="below_movie_left" id="printableArea"> My printing contents </div> <input type="button" class="submit_button" onclick="printDiv('printableArea')" value="Print" style="float:right;" /> <script> function printDiv(divName) { var printContents = document.getElementById(divName).innerHTML; var originalContents = document.body.innerHTML; document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; } </script> 

Is this possible with the javascript / jQuery / Ajax method? as?

+6
source share
2 answers

If you already have the page you want to print, put this page in a hidden iframe and print the contents of the iframe

 <iframe src="letterprint.php" name="frame"></iframe> <input type="button" onclick="frames['frame'].print()" value="printletter"> 
+16
source

You cannot print another page; browsers just don't give Javascript this power. However, you can change the contents of the page where the user is located.

In short, you can use AJAX or iframe to access the second page (letterprint.php), and then replace the contents of the element on your page with the contents of this page. If you do not want it to be visible to the user, you can use the target stylesheet so that new content is displayed only when printed. A.

+1
source

Source: https://habr.com/ru/post/969416/


All Articles