[thelist] JavaScript: Print Then Close

Sarat Pediredla sarat.pediredla at gmail.com
Thu Jan 12 15:01:42 CST 2006


> It's all working but closing the new window:
>

(Note: Sorry for the copy pasted code. It is quite small and hence I
took the liberty of pasting it)
Try this in the "parent" window (the window which opens the popup).

<html>
<head>

</head>
<body onLoad="openpage();">
<script language="JavaScript"><!--
function openpage()
{
msgWindow=window.open('test.html','popwindow','resizable=no,width=200,height=200');
if (msgWindow.opener == null) msgWindow.opener = self;
}
//--></script>
</body>
</html>

and then in the child/popup window

<html>
<head>
 <title>Page to Print</title>
</head>
<body onload="printpage()">
<script language="Javascript">
<!--
function printpage() {
 window.print();
 this.close();
}
//-->
</script>
Text Here
</body>
</html>

I have tested this in IE but I dont see why it shouldnt work on others.

Finally, I have to make a point about unobtrusive javascript. Using
onLoad inside tags defeats the point of usability or good coding. I
feel a bit evangelical these days , so I will refer you to
http://www.webstandards.org without further ado.
--
-----------------------------------------------------
Regards,
Sarat Pediredla
Blog: http://sarat.xcelens.co.uk "Talking a lot about nothing"



More information about the thelist mailing list