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

Printing with javascript

Status
Not open for further replies.

Tagaca

Programmer
Feb 16, 2001
5
US
I need to print a page using javascript without having to view or load the page first. Does anyone know if this can be done, and if so how?

I have been trying
winhandle = window.open(url, "");
winhandle.print();
winhandle.close;
 
Well I have been told you can print iframes, but I have not had success. This will work actually, but make sure the page loads first - in the page you open in the new window insert in the body:

onLoad="self.print();self.close()";

Then the print box opens - and the window will close as soons as that closed. You could put this code in your opener page I suppose too.

winhandle.onLoad = "self.print();self.close()";
b2 - benbiddington@surf4nix.com
 
This works, however a confirmation box pops up to confirm that you
want to close the window. Is there anyway to prevent this alert message from
coming up when using the close() method?
 
I think that if you use the parent window (ie the window that opened the new window), you can close the new window without any errors.


do these,

change your open window line to this:

window.open(url,'childWindow');

add this function to your parent window:

function closePrinter(){childWindow.close();}

change the onload handler in the printer window to this:

onload="window.print();parent.closePrinter();"



now, that SHOULD work :) theEclipse
eclipse_web@hotmail.com
**\\||It was recently discovered that research causes cancer in rats||//**
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top