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.