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

caputring content of div for printer friendly pages?

Status
Not open for further replies.

spastica

Programmer
Sep 27, 2002
72
0
0
GB
My website is set up so that the main body content is containted within a div. I would like to create printer-friendly pages which show only the content in the div.

I am able to do this with the following code, but it hangs in firefox and netscape. Is there another, better way to capture the content of a div and display it in a new window/same window? Even if Asp or a server side language needs to be used?

function screenshotwindow()
{
var generator=window.open('','name','toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=1,width=540,height=500');
var printDaDiv=document.getElementById('mainContent').innerHTML;
var printDaHeading=document.getElementById('mainheading').innerHTML;
generator.document.write('<?xml version=\"1.0\"?>');
generator.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " generator.document.write('<html xmlns=" generator.document.write('<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />');
generator.document.write('<title>Testing<title>');
generator.document.write('<link href="stylesheet/htstyles.css" rel="stylesheet" type="text/css" />');
generator.document.write('</head>');
generator.document.write('<body>');
generator.document.write(printDaHeading + printDaDiv);
generator.document.write('</body></html>');
generator.document.close();

}

i am calling it using: <a href="javascript:screenshotwindow('mainContent','')">test</a>
 
How does it hang, what message do u get in javascript console ?
P.S : type "javascript:" in adress tio get javascript console.

Water is not bad as long as it remains outside human body ;-)
 
thanks - I don't get an error message - the content loads, but the "egg timer" appears and doesn't go away - the status bar also remains active and doesn't fully complete the loading of the page.

I'm not sure what the problem could be?!
 
Before this line:

Code:
generator.document.write('<?xml version=\"1.0\"?>');

you should add this line:

Code:
generator.document.open();

I'm not sure if it will fix your issue or not, but worth a go.

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 

Incidentally, you can have a print-only style sheet for you page without resorting to opening specific print-friendly pages. I'd ask in the CSS forum (forum215) for more info on this, if you're interested.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top