For printing my Aspx web page I use following code but in IE I encounter “Stack over flow at line:0” error message and in fire fox any thing doesn’t happen.
what’s wrong?
<head>
<script language="javascript" type="text/javascript">
function print() {
window.print();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="toolbar" style="width:400px">
<ul>
<li>
<img alt="" src="../../../CssImages/printer_128.png" id="ImgPrint" width="20px" style="cursor:pointer" onclick="print()"/>
</li>
</ul>
Your function:
will put
printinto the global object aswindow.print. So in fact you’re calling the function itself, which calls itself, etc. This will continue forever which causes an overflow.Because
window.printis already defined natively, why not eliminate the custom function? If you removefunction print() {...}it should work fine, because it will then call the ‘real’window.print(asprintis just a shortcut towindow.print), which actually does the printing.