Click to See Complete Forum and Search --> : document.print()


im_wclaa
12-30-2002, 01:39 AM
hi all,
I tried to use the below function to print my webform written in asp.net when I click the "print" button. But a statment "error on page appears" in the status bar in IE. Does anyone know what is the problem?(Note: it goes fine when I use window.print();)
<script LANGUAGE="JavaScript">
function printWindow() {
document.print();
}
</script>

Zach Elfers
12-30-2002, 02:12 AM
Use "document.write();" instead.

im_wclaa
12-30-2002, 02:23 AM
hi,
I have tried but when I click the button. The page is not printed out. The page just "hanged" instead. Thx.

Zach Elfers
12-30-2002, 02:27 AM
OOPS!!! I wasn't even thinking right. It's 3:30 a.m. where I am and I told you document.write();. I am so stupid. documen.write() is used to put text on a page.

im_wclaa
12-30-2002, 02:31 AM
hi,
It's fine and still thx ur effort. But do u have any other ideas?

Zach Elfers
12-30-2002, 02:38 AM
Maybe:

this.document.print();

???

im_wclaa
12-30-2002, 03:13 AM
hi,

It is still not ok. I dont know why. I wanna ask if u have used document.print() before? Does it works?

Actually, why I use it becoz I wanna print the form without showing the scroll. Do u have any other suggestion to do that?
Thx.

Charles
12-30-2002, 04:59 AM
It's window.print and not document.print and it only works in MIcrosoft and then only when the user has not disabled scripting. To avoid a link to nowhere use JavaScript to draw the link only when it will work:

<script type="text/javascript">
<!--
if (window.print) {
document.write('<a href="#">Print this page.</a>');
document.links[document.links.length-1].onclick = function () {window.print(); return false};
};
// -->
</script>