Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print and close window 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
I have a print button on a screen which, when clicked, I want to open a new window, print the contents and close it. However, it's not working.

The window will open and print but it's not closing.
I have the window.print() function called onLoad and then am trying to use the window.onafterprint() to call the window.close function.

Any ideas why this doesn't work. I put a debug message in the onafterprint function and it appears to be calling this function even before the page prints.

Mighty :)
 
in my test, both onbeforeprint and onafterprint fired before my printer dialog appeared:

<html>
<head>
<title></title>
<script type=&quot;text/javascript&quot;>
window.onbeforeprint = function () {
alert(&quot;before&quot;);
}
window.onafterprint = function () {
alert(&quot;after&quot;);
}
</script>
</head>
<body>
</body>
</html>



=========================================================
while (!succeed) try();
-jeff
 
Jeff,

Thanks for the info - I found some information on the Microsoft site which basically said that it won't work.

Mighty :)
 
Hi,

Just &quot;queue&quot; up the commands:

window.open....
window.print(); the print dialogue will appear.
window.close();

This will work nicely.
 
Thanks jjangli,

That worked a treat. I never thought of doing it that way!!

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top