...

View Full Version : Code Dosent work any Idea Why?



Pc__girl
01-03-2004, 05:25 PM
Hi all,

I was givent this code and it dosent work and I dont have enough expirence to know why, can anyone help or is it even possible to do this?

My intent is that when clicking on this link it prings up a page that is printable and then closes the window afterwards.

</FORM>


<SCRIPT LANGUAGE="JavaScript">
function OpenPrintPage()
{
var wNew = window.open("PrintAndClose.htm","junkWindow");
}
</script>

<form> <p align=center>
<input type=button name=print value="Print the SETR Chart"
onClick="OpenPrintPage()">
</form>

oracleguy
01-03-2004, 06:10 PM
Worked for me.

Skyzyx
01-03-2004, 06:17 PM
Well, all this code does is open a new window... that's it.


Originally posted by Pc__girl
My intent is that when clicking on this link it prings up a page that is printable and then closes the window afterwards.

Closes the window after what? After it prints? There's no way for JavaScript to know when the page has been printed. You can have this script open the appropriate printer-friendly page, and on that page have a script that opens the print dialog, but the user will have to close the window manually.

On the other hand, the next closest thing would be to have the new window open, that window opens a print dialog, and then moves itself to the background, and using setTimeout() to close the window after a number of seconds... but you won't know if the user is modifying his printing preferences (which I do on a regular basis), so it may be hard to calculate when to close the window.

Personally, I would leave the thinking to the users. It might not be a good idea to take that decision-making process away from them...

josses
01-03-2004, 07:49 PM
it is quite simple actually

on the page that opens the window simply have your script that opens the window your open window function
<script>
function mywindow(myloc,myname){
window.open(myloc,myname)
}
</script>

onClick="mywindow('printpage.htm','junkwindow')"

on the page you want to print insert the following code into the
onLoad of the body

<body onLoad="window.print();window.close();">

that is what i do anyways. but if you notice that it isn't printing the page properly remove the onload from the body and at the bottom of the page insert this code
<script>
window.print();
window.close();
</script>

this should work if th onload doesn't

Pc__girl
01-04-2004, 12:25 AM
Hi all I told you I didnt know what I was doing I gave you the wrong script it was to have been this. Ill try what was suggest and see what happens.
Thanks!
<script language="JavaScript">
function DoPrint()
{
if(window.print)
{
var strOut;
if (navigator.appName == "Netscape")
{
strOut = "Be sure to use the Landscape setting!\n\n"
+ "Unfortunately, Netscape's scripting is not as capable as Internet Explorer's.\n"
+ "Netscape users must manually close this 'Printable SETR Image' page.\n"
+ " via File->Close Window.";
}
else
{
strOut = "Be sure to use the Landscape setting! Are you printing in color?";
}

alert (strOut);
window.print();
}
}

function AfterPrint()
{
// It seems we absolutely MUST have a dialog here.
// Otherwise, the print job never happens ):
// Maybe we could locate some kind of 'Sleep' function
// to force a small pause that doesn't depend on the user
// to interact with us.
alert ("'OK' to finish print job....");

window.close();
}
</script>

Skyzyx
01-04-2004, 05:56 AM
Originally posted by Pc__girl
+ "Unfortunately, Netscape's scripting is not as capable as Internet Explorer's.\n"

AH-HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA!!!
:rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum