如何从Web浏览器的打印弹出窗口中了解单击(确定或取消)事件

时间:2012-03-01 10:05:17

标签: c# javascript

在我的应用程序中,我通过弹出窗口打印一些数据。加载弹出窗口时,将提示用户打印或取消。我想知道点击了哪个按钮(打印或取消),以便我可以根据点击的按钮采取一些操作。代码和截图如下所示。

public void Print(int Id)
        {
            StringBuilder sb = BadgeHelper.preparePrintableString(Id);
            string printWindowFunc = "function printWindow() {\n" +
                                        "var z = window.print();\n alert('Return: ' + z);\n" + 
                                        "checkDocumentState();\n" +
                                      "}";
            string checkDocumentStateFunc = "function checkDocumentState() {\n" +
                                                "if (document.readyState == 'complete') {\n" +
                                                    "window.close();\n" +
                                                "}\n" +
                                                "else {\n alert('Else');\n" +
                                                    "setTimeout('checkDocumentState()', 2000);\n" +
                                                "}\n"+
                                            "}\n";

            string startingHTMLCode = "<html>\n" +
                                        "<head>\n" +
                                            "<script type='text/javascript'>\n " +
                                                checkDocumentStateFunc + 
                                                "\n" +
                                                printWindowFunc +
                                            "</script>\n " + 
                                        "</head>\n" +
                                        "<body onload='printWindow();'>\n";
            sb.Insert(0, startingHTMLCode);
            sb.Append("\n</body>\n</html>");

            Response.Write(sb.ToString());
        }

enter image description here

0 个答案:

没有答案