View Full Version : Printing a page without opening it ... is this possible?

08-15-2005, 06:53 PM

I've got a little bit of javascript to print a page from another page, as follows:

In the javascript:

function printpage(url)
child = window.open(url, "", "height=1, width=1"); //Open the child in a tiny window.
window.focus(); //Hide the child as soon as it is opened.
child.print(); //Print the child.
child.close(); //Immediately close the child.

In the HTML:

<input type="button" value="print another page" onclick="printpage('another.html');">

This gives the illusion of printing a page (or you could print several pages by extending printpage) from a link in a different page without actually opening the other page (although we all know it does actually open the other page, it just hides it immediately and gets rid of it when printing is done).

Is there any way of truly printing another page without opening it?


08-15-2005, 07:57 PM
You will have to open it somewhere. Where it is opened, now, that's another story. You can hide it in an "invisible" iframe/frame, use xmlhttprequest to stream it to a new document and print that, or go another route.
But the client has to see it sometime and all you get from plain old javascript is the window.print command.
If this is for an intranet app, you may have a couple more options that are MSIE only, but in general, you'e stuck just hiding it somewhere.

08-15-2005, 11:54 PM
Thanks for that info, I might try fiddling with the invisible iframe solution - the current solution is satisfactory, but it does cause the child window to "flicker" into the user's view and then be immediately hidden. I like the invisible iframe solution - no "flicker"! Probably also immune to pop-up blockers, I should imagine ...