Click to See Complete Forum and Search --> : function WinOpen()
marshall_73
07-29-2003, 06:19 PM
Hi,
Can someone help me out (again :D )??
Here is the script:
<script language="JavaScript">
function WinOpen() {
msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no");
msg.document.write("......");
msg.document.write(".......");
msg.document.write(".......");
window.print();
}
</script>
<body>
<input type="button" value="Printen" name="B3" style="font-family: Arial Rounded MT Bold; color: #000044" onClick="WinOpen()">
</body>
The "window.print()"-statment on the bottom of the script,
prints the current window (the one the button is on), but I want it to print the window wich is just created with the WinOpen()-function (after clicking the button of course). Is this possible in one function, because I don't know how to put a function in a function.
Many thanks,
M.
webHeretic
07-29-2003, 06:41 PM
Would you be against the following solution?
Create a new html called displayWindow.html and put the following code in it.
<HTML>
<head>
<script language="JavaScript">
window.print();
</script>
</head>
</HTML>
change your open statement to:
msg=open("displayWindow.html","DisplayWindow","toolbar=no,directories=no,menubar=no");
webHeretic
07-29-2003, 06:45 PM
Hmm, my printer is on the fritz so I couldn't test my last solution thoroughly. I'm not sure if the document.writes will get there fast enough since the window.print() gets called as soon as the window opens.
angrytuna
07-29-2003, 06:49 PM
As far as I know, window.open returns a handle to the window that was just opened. You can use that handle to print the window. Have you tried this?:
<script language="JavaScript">
msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no");
msg.document.write("......");
msg.document.write(".......");
msg.document.write(".......");
msg.print();
</script>
AT
webHeretic
07-29-2003, 06:55 PM
I tried that and it didn't work on my Machine. You would think that a parent window would have access to the Print method of the child but it apparently doesn't.
webHeretic
07-29-2003, 07:33 PM
Fascinating...
function WinOpen() {
msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no");
//msg.document.write("......");
//msg.document.write(".......");
//msg.document.write(".......");
msg.print();
}
...with the document.writes commented out, the msg.print function works. Uncomment the document.writes and it doesn't. I thought it was a focus issue with the child getting focus so the msg.print method would never be called from the parent. I tried adding onBlur=window.focus to give the parent focus and then call msg.print but that didn't work either.
Sorry, I know this isn't an answer but it's info that may help someone else solve the problem.
marshall_73
07-30-2003, 04:14 AM
Originally posted by webHeretic
Sorry, I know this isn't an answer but it's info that may help someone else solve the problem.
No problem. thanx for your time anyway. I think I have to try another thing. It is very dissapointing that so many thing can be done with JS, but a simple thing like this seems impossible :D
Gr. M.
marshall_73
07-30-2003, 05:57 AM
Originally posted by webHeretic
Sorry, I know this isn't an answer but it's info that may help someone else solve the problem.
No problem. thanx for your time anyway. I think I have to try another thing. It is very dissapointing that so many thing can be done with JS, but a simple thing like this seems impossible :D
Gr. M.
MikeOS
07-31-2003, 09:48 PM
Here is the solution (running on from your code) you seek. It has the added advantage of ensuring the page in the new window has fully loaded before the print() method is called; this is ensured as the script closes the document stream beforehand. Although it works fine it isn't the way I would do it.
<html>
<script language="JavaScript">
var msg;
function WinOpen() {
msg = open("","DisplayWindow","toolbar=no,directories=no,menubar=no");
msg.document.open()
msg.document.write("......");
msg.document.write(".......");
msg.document.write(".......");
msg.document.close()
msg.print()
}
</script>
<body>
<input type="button" value="Printen" name="B3" style="font-family: Arial Rounded MT Bold; color: #000044" onClick="WinOpen()">
</body>
</html>