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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent - Simple: How to close browser after print?

Status
Not open for further replies.

shdale

Programmer
Nov 18, 2008
4
0
0
GB
Hello all,

I'm not a javascript programmer and this is very simple - I know but I really dont know what to do here. I know you can help!

I have the following code and I need 'something' added to close the browser window after the print has completed.


<code>

<script type="text/javascript">
var pwin;
function printImg(printOption) {
var imageToPrint = document.getElementById("imgMain").src;
var html = imageToPrint;
if (printOption == 'option2') {
html = '<html><head><style type="text/css">img { float: left; margin: 0; padding: 0;}</style></head><body>';
html += '<img src="' + imageToPrint + '" alt="" width="105" height="57">';
html += '<img src="' + imageToPrint + '" alt="" width="105" height="57">';
html += '<br clear="both">';
html += '<img src="' + imageToPrint + '" alt="" width="105" height="57">';
html += '<img src="' + imageToPrint + '" alt="" width="105" height="57">';
html += '</body></html>';
pwin = window.open('', "_blank");
pwin.document.write(html);
pwin.document.close();
} else {
pwin = window.open(html, "_blank");
}
setTimeout("pwin.print()" ,20);
}
</script>

</code>

Thankyou for your help!
 
There is no way to explicitly be sure that your user successfully printed the page using JavaScript. You could potentially write some ActiveX to do this, but it's not worth the effort.

[tt]window.close()[/tt] will close the browser window. Note that the user will be prompted with a "the browser is attempting to close this window" message prior to closing.

You could try setting a variable just before the page prints, and then check the variable value upon browser focus, and close the window then, but still, if the user cancels the print the browser would attempt to close.

----
 
Hi, thanks for your suggestion. I am afraid I dont know how to implement this. Giving my code (previoulsy posted), what should I add to this/change?
Many thanks,
Sheila
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top