0

When I run through the JS in developer tools, it shows all the data from the innerHTML but the print only shows blank pages with the date. Any feedback is appreciated.

function PrintThisPage(sectionName) {
var sOption = "toolbar=yes,location=no,directories=yes,menubar=yes,";
sOption += "scrollbars=yes,resizable=yes,status=yes,width=750,height=600,left=100,top=25";

var sWinHTML = document.getElementById(sectionName).innerHTML;
var winprint = window.open("", "", sOption);
winprint.document.open();
winprint.document.write('<html><head>');
winprint.document.write('<LINK href="../stylesheets/main.css" type="text/css" rel="stylesheet">');
winprint.document.write('<LINK href="../stylesheets/FormEdit.css" type="text/css" rel="stylesheet">');
winprint.document.write('</head>')
winprint.document.write('<body style="display:none">');
winprint.document.write(sWinHTML);

arrInputs = winprint.document.getElementsByTagName('input');
for (i = 0; i < arrInputs.length; i++) {
    if (arrInputs[i].type == "image" || arrInputs[i].type == "button" || arrInputs[i].type == "submit") {
        arrInputs[i].style.display = 'none';
    }
}

arrInputs = winprint.document.getElementsByTagName('td');
for (i = 0; i < arrInputs.length; i++) {
    arrInputs[i].onmouseover = null;
}

winprint.document.write('</body></html>');
winprint.document.body.style.display = '';
winprint.document.close();

if (window.print) {
    winprint.print();
}
else {
    alert("Sorry, the print ready feature is only available in certain browsers.");
} // end - if (window.print)

}

Edit

imgPrint.Attributes["onclick"] = string.Format("PrintThisPage('{0}');",       divDataContent.ClientID);

When I run this in chrome, I get an exception: {System.Web.HttpException (0x80004005): Cannot get inner content of divDataContent because the contents are not literal.

Edit 2

I receive the same error in IE, but the functionality still works.

Edit 3

Apparently Chrome doesn't like document.write, so I modified it to document.body/head.innerHTML.

Thanks everyone.

0 Answers0