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
LVL 1
darcosysAsked:
Who is Participating?
 
b0lsc0ttIT ManagerCommented:
There is no such event.  You will have to use a timeout.  The time in the line below is in millisecond so adjust as needed for the page to get to the spooler.

self.setTimeout('window.close()', 5000); // 5 seconds

Depending on where the script is you may have to change the self or window part.  Let me know more about the scripts you have and where they are if you need details on using it.

bol
0
 
b0lsc0ttIT ManagerCommented:
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
0
 
darcosysAuthor Commented:
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.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
ShaDowQCCommented:
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"...
0
 
darcosysAuthor Commented:
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);      )
0
 
darcosysAuthor Commented:
<body leftmargin="0" topmargin="0" onload="prnt()">



function prnt(){
window.print()
self.setTimeout('window.close()', 5000);
}
0
 
ShaDowQCCommented:
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.
0
 
b0lsc0ttIT ManagerCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.