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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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();\">";
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

Try putting them in an iframe.
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
Post Reply