本文介绍了Javascript Window.Print在Master Page中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,
I am having same javascript as below and I am using that in my Master Page.
But when I try to print;
It is showing me error on line:-
printWindow.document.write(printContent.innerHTML);

Thanks.

 <script type="text/javascript">
                function printPartOfPage() {
                    var printContent = document.getElementById("ContentPlaceHolder2");
                    var windowUrl = 'about:blank';
                    var uniqueName = new Date();
                    var windowName = 'Print' + uniqueName.getTime();
                    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

                    printWindow.document.write(printContent.innerHTML);
                    printWindow.document.close();
                    printWindow.focus();
                    printWindow.print();
                    printWindow.close();
                }
</script>


<div id="body">	
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">

</div>


HyperLink9.NavigateUrl = "javascript:window.printPartOfPage()";
HyperLink9.Text = "Print this Page";

推荐答案

NavigateUrl="javascript:window.printPartOfPage(this)"



并预先配置你的功能


and pre configure your function that

function printPartOfPage(strid) {
             var printContent = strid;
             
                    var windowUrl = 'about:blank';
                    var uniqueName = new Date();
                    var windowName = 'Print' + uniqueName.getTime();
                    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
 
                    printWindow.document.write(printContent.innerHTML);
                    printWindow.document.close();
                    printWindow.focus();
                    printWindow.print();
                    printWindow.close();
                }





我尝试过它



i tried it worked


这篇关于Javascript Window.Print在Master Page中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 14:09