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

Need to get a pop-up to print 1

Status
Not open for further replies.

jamesp81

Programmer
Mar 3, 2006
19
US
I am creating a pop-up window to display information specifically for printing. The page the pop-up is launched from calls an external javascript function which takes the information to display as text and scripts out all the HTML when it creates the page. The function scripts out HTML and javascript for two buttons: Close and Print. My close button works fine. When I try to use my print button, however, nothing happens. Strangely enough, if I refresh the pop-up after pressing the print button, then my print dialog will open, almost as if the page is playing catch-up. Does anyone know that I'm doing wrong.
 
stripping out HTML is probably not a good start.

do you have a link to show us? if not, may i suggest opening your popup print window in a browser, doing View > Source, and then copying and pasting your code into this thread, if it's not incredibly long.



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I think you misunderstand. I'm not stripping the HTML out. In fact, I'm verbatim copying the HTML of the part of the main page I want and sending it to a script to create a new page with it.

The function the creates my new page is as follows:

function printerfriendly(displayhtml)
{
generator=window.open('/print.html','name','height=400,width=500,menubar=yes,titlebar=yes,scrollbars=1,resizable=yes');

start_erase = displayhtml.lastIndexOf('<P style', displayhtml.indexOf('pfgraphic'));

end_erase = displayhtml.indexOf('</P>', displayhtml.indexOf('pflink'))+4;

mystring = displayhtml.replace(displayhtml.substring(start_erase, end_erase),'') + '<center><input type="button" value="Close" onclick="javascript:window.close()"></input><input type="Button" value="Print" onclick="javascript:window.print()"></input></center>';

generator.document.write('<html>');
generator.document.write('<head>');
generator.document.write('</head>');
generator.document.write('<body>');
generator.document.write(mystring);
generator.document.write('</body>');
generator.document.write('</html>');
}

This is called from another page when the user clicks on the appropriate link and it constructs and then opens my pop up page. Most of this nasty looking code is taking in the HTML I want for the pop up and cutting the other out. The bolded text is the definition of the Print button on the pop-up.

If you wish to look at a link try Click on the link labeled Printer Friendly.
 
try a [tt]generator.document.open()[/tt] immediately before your first call to the write() function and a [tt]generator.document.close()[/tt] immediately after your last call to the write() function.



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top