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>
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>