Page 1 of 1

Need a Print link that will print a PHP file, but not open.

Posted: Thu Jul 10, 2014 7:56 am
by simonmlewis
I have a print-friendly version of a dynamic page, using a separate CSS file.

I want to be able to open that PHP file to auto-print (which can be done easy with onload="window.print"), but I'd prefer it if that page didn't actually "open on screen".

It doesn't matter if it must, but would be good if I could do it the way one does it with Windows, where you select a group of files, and choose print. It prints them without actually opening them up on screen.

Can it be done?

I tried a timeout onload too, but that didn't work.

Code: Select all

echo "<body onload=\"window.print()\">

<script language=\"JavaScript\" type=\"text/javascript\">
function winClose()
{
window.setTimeOut(\"window.close();\",10)
}
</script>

<body onload=\"winClose();\">";

Re: Need a Print link that will print a PHP file, but not op

Posted: Thu Jul 10, 2014 1:19 pm
by Christopher
Try putting them in an iframe.

Re: Need a Print link that will print a PHP file, but not op

Posted: Thu Jul 10, 2014 2:27 pm
by requinix
You cannot force the browser to print something automatically (at least not without using client-side Flash/Java). The closest you can get is calling window.print() like you're doing now.