使用javascript写入新窗口...获取拒绝访问权限

时间:2010-04-09 10:37:07

标签: javascript

我一直在努力解决这个问题,并决定是时候寻求帮助了。

我正在尝试在aspx页面上创建一个打印功能,我正在使用javascript来执行此操作:

        function PrintContentCell() {
        var display_setting = "toolbar=yes, location=no, directories=yes, menubar=yes,";
        display_setting += "scrollbars=yes, width=750, height=600, left=100, top=25";

        var content_innerhtml = document.getElementById("testTable").innerHTML;

        var document_print = window.open("Loading.htm", "", display_setting);
        document_print.document.open();
        document_print.document.write('<html><head><title>Print</title></head>');
        document_print.document.write('<body style="font-family:verdana; font-size:12px;" onLoad="self.print();self.close();" >');
        document_print.document.write(content_innerhtml);
        document_print.document.write('</body></html>');
        document_print.print();
        document_print.document.close();
        return false;
    }

当脚本尝试写入新窗口时,我收到“拒绝访问”。 Loading.htm文件只是一个非常纤薄的html文档,写出了文本“正在加载...”。我曾希望在阅读这篇帖子之后这会有用:IE 6/7 Access Denied trying to access a popup window.document

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:3)

如果你想要一个新的空弹出窗口写入,通常的方法是使用一个空字符串作为URL:

window.open('', '_blank', features)

当您甚至在有机会加载之前立即替换所有内容时,尝试从服务器打开HTML是毫无意义的。 (您的空窗口名称""也可能会导致问题。)

但是,这无论如何都不是实现页面“打印版本”的好方法。相反,请使用隐藏testTable内容以外的所有内容的print stylesheet

答案 1 :(得分:0)

创建空(.write())弹出窗口后,你能不能简单地window.open("", ...)“加载”标记?

它可以避免访问服务器,似乎对用户更敏感并解决您的问题。

编辑事实上,正如您刚刚在客户端传输的数据一样,渲染HTML所需的时间是否真的需要加载横幅?