Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Print a pop-up window

Posted on 2007-10-19
8
Medium Priority
?
485 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:darcosys
  • 3
  • 3
  • 2
8 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20111010
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
 
LVL 1

Author Comment

by:darcosys
ID: 20111085
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
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 20111155
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:ShaDowQC
ID: 20111308
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
 
LVL 1

Author Comment

by:darcosys
ID: 20111319
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
 
LVL 1

Author Comment

by:darcosys
ID: 20111323
<body leftmargin="0" topmargin="0" onload="prnt()">



function prnt(){
window.print()
self.setTimeout('window.close()', 5000);
}
0
 
LVL 1

Expert Comment

by:ShaDowQC
ID: 20111353
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20111411
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question