Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

104 of 124 people (84%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Why doesn't window.print() work in a child window which is opened using the window.open method

Apr 5th, 2008 20:30
ha mo, Gerry Baldwin, Dangelo Sugar, Colin Fraser, Guest, irt.org


I am not convinvce the problem lies with the window.open method, I think
that it is more likely that print() is being called wrongly.
Try this: 
<script language="JavaScript">
<!--
function SymError()
{
  return true;
}
window.onerror = SymError;
//-->
</script>
<script>
var childwin=new Object;
   childwin.location = childwin; 
   windowReference = childwin;  
</scritp>
The using a form : 
<form>
<input type="button" value="Print Child" onclick="if (window.print)
windowReference.print()">
</form>
You will have to change this to suit your particular need, but this
should provide a working solution
Actually, the problem lies in the child window not the actual print().
to solve the problem.
newWindow = window.open(...) \\opening child window
newWindow.location.reload( false ); \\ refreshes the child window
\\ for some reason, the child window has to be refreshed
\\ *** in child window ***
<input type=button onclick='window.print();'>
This should do the TRICK!!!
The window.print() command stalls because the new window is still open 
for input. If one closes with windowName.document.close(); the print 
command works as expected.
Try this:
<HTML>
<HEAD>
<TITLE>Print Child Window</TITLE>
<SCRIPT>
function printChildWindow() {
	var newWindow = window.open
("newWindow.html", "newWindow", "height=200,width=300");
	newWindow.document.write('<HTML><HEAD><TITLE>Print 
Daughter</TITLE></HEAD><BODY><CENTER><BR><BR>This is some 
data.<BR><BR><BR><INPUT TYPE="button" NAME="print" VALUE="Click to 
Print" ONCLICK="window.print()"></CENTER></BODY></HTML>');
	newWindow.document.close(); //This is the key!!!
	}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<BR><BR><BR>
<INPUT TYPE="button" VALUE="Click to Create New Window" 
ONCLICK="printChildWindow();">
<CENTER>
</BODY>
</HTML>
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com