Link to home
Start Free TrialLog in
Avatar of darcosys
darcosys

asked on

Print a pop-up window

I want to print a page but with this steeps.

1.- Open a window
2.- When the page load complete , print the page.
3.- Close the window.

there are some event like onfinishload then i can call the function print
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

darcosys,

Use onload.  Is the content or page in the popup on your server and domain?  Can you add code to it or do you want the main (opener) window to do this?

The simplest method is in the body tag in the html for the popup.  Call the print function.

<body onload="window.print();">

Let me know if you have any questions or need more information.

b0lsc0tt
Avatar of darcosys
darcosys

ASKER

ok, that's great but , now , how can i close the pop up window.
I tried this      onafterprint="window.close()"    but it doesn't work.
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't see why you want a popup that print then close itself.. The user does any interaction in this window?

You know that if it is just because you want to print something different that the current page you are on (like a different content). There is a clean way to do it with CSS. With media="print"...
i'm developing on asp.net then, when i save the data i call the window for print a report
something like      window.open('report_print.......')       i only want this page for print the report, i don't have javascript code, only fill the report and i want to print (that's ok) but the window keep opened.

sorry my grama but i don't speak english very well  :)

thanks a lot, it work  (    self.setTimeout('window.close()', 5000);      )
<body leftmargin="0" topmargin="0" onload="prnt()">



function prnt(){
window.print()
self.setTimeout('window.close()', 5000);
}
The set timeout is pretty useless if you don't want the user to really see the page.. you can do

<body leftmargin="0" topmargin="0" onload="prnt()">
function prnt(){
window.print()
window.close()
}

The javascript will wait after the user decision about printing or not before closing.
I'm glad I could help.  Thanks for the grade, the points and the fun question.

You should keep the timeout.  Just answering the prompt to print won't provide enough time for the browser to process and get the page to the spooler.  The popup will need to be up for at least a few seconds, even with the most simple of pages.

bol