使用动态HTML打印预览窗口 [英] Print preview Window with dynamic HTML

查看:159
本文介绍了使用动态HTML打印预览窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends,



我需要使用动态html创建一个类似'Print Preview'窗口的精确内容。所以我考虑了如下选项:



Hello Friends,

I have a requirement to create an exact stuff like 'Print Preview' window with dynamic html. So I considered an option as below:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <title></title>
    <script type="text/javascript">
        function PrintPanel() {
            var panel = document.getElementById("<%=pnlContents.ClientID %>");
            var printWindow = window.open('', '_blank', 'Toolbar=0,Location=0,Directories=0,Status=0,Menubar=0,Scrollbars=0,Resizable=0');
           // printWindow.document.write('<html><head><title>DIV Contents</title>');
            //printWindow.document.write('</head><body >');
            printWindow.document.write(panel.innerHTML);
           // printWindow.document.write('</body></html>');
            printWindow.document.close();
            setTimeout(function () {
                printWindow.print();
            }, 500);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Panel ID="pnlContents" runat="server">
            <span style="font-size: 10pt; font-weight: bold; font-family: Arial">Hello,
            <br />
                This is <span style="color: #18B5F0">Hello!!! SAM</span>.<br />
                Hoping that you are enjoying my articles!</span>
        </asp:Panel>
        <br />
        <asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="return PrintPanel();" />
    </form>
</body>
</html>





但是我遇到了这方面的问题做法。它当然打开一个带window.open的窗口,但原始打印预览只在模态弹出页面而不是新窗口中打开。 window.open打开一个新窗口,显示在打印预览的后面。我不想要那个新窗口。朋友可以帮忙吗?



But I am facing problems with this approach. It certainly opening a window with window.open but original print preview opens in the same page only as modal pop up page rather than new window. the window.open opens a new window which appears behind the print preview. I dont want that new window. Friends can you please help?

推荐答案

那个窗口打开因为你正在打电话, window.open() [ ^ ]然后你只是在printWindow变量中存储对该窗口的引用。删除该行代码,您的弹出窗口将不会出现。其余的对象将保持原样。



然后打开打印窗口,因为你也调用了这个函数, printWindow.print(); 可以用此函数替换, window.print(); [ ^ ]做同样的事情;显示打印对话框(预览)。实际上,这不是预览,它只是文档的设置,然后再将其发送到打印机。
That window opens because you're calling, window.open()[^] and then you're just storing the reference to that window in printWindow variable. Remove that line of code and your pop up window won't come. The remaining objects would remain as they are.

The print window then opens because you call this function too, printWindow.print(); which can be replaced by this function, window.print();[^] which does the same thing; shows the print dialog (a preview). Actually, that is not a preview, it is just the settings for your document before sending it to the printer.


这篇关于使用动态HTML打印预览窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆