开发者

Window.print() fails to print

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:

function print() {
    window.print(); // <-- refers to this custom function
}

will put print into the global object as window.print. So in fact you're calling the function itself, which calls itself, etc. This will continue forever which causes an overflow.

Because window.print is already defined natively, why not eliminate the custom function? If you remove function print() {...} it should work fine, because it will then call the 'real' window.print (as print is just a shortcut to window.print), which actually does the printing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜