Trying to print an external HTML file using javascript. The code works in IE. However, in Google Chrome and Mozilla FireFox, it does not print the external page, it prints the current page. Any suggestions?
Header Code
<link rel="alternate" media="print" href="file.htm" />
Body Code
<a href="file.htm" onclick="window.print(); return false;">Print Agreement</a>
Google Chrome loads its "chrome://print/" for print preview, maybe causing this issue. Is there another way of doing this? So far the only workaround I can get is to open a popup and have the user print from there... But it's an extra step that seems pointless, and no one likes pop-ups anymore.
Cheers.
JavaScript | Window print() Method. Page print in JavaScript is a simple code in JavaScript used to print the content of the web pages. The print() method prints the contents of the current window. It basically opens Print dialog box which lets you choose between various printing options.
In the above syntax, we use the window. print() method that prints the currently visible content of the window screen. Parameters: It does not contain any parameters. Returns: The window.
Open a webpage in Chrome, press Ctrl+P to open the Print dialog and change the destination printer to “Save as PDF”. Hit the “Print” button and the webpage will download as a PDF document. You can also use Chrome's print-to-PDF function to convert to .
You should try to give users option to view first the Agreement, not directly print it. And, if you do so, you can invoke printing from the Agreement itself, with a button for example, it can be also a link, using simple HTML/JavaScript code:
<input name="print" type="button" id="print" value="Print agreement" onclick="window.print();"/>
I personally use this approach and works even with IE5.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With