1

我正在处理一些旧的遗留 ASP 代码,用户可以在其中上传/附加多个文件。文件存储在数据库中,应请求(单击显示附件.asp?attachmentGuid=....的链接)应显示/下载附件。就像在尝试通过 iframe 使用 jQuery 模式弹出displayattachment.asp 页面集标题查看 pdf 文件一样

Content-Disposition: inline; filename="somefile.ext"

在客户端,我有一个带有 iframe 的 jquery 对话框:

function DisplayAttachmentWindow(sAttachmentGuid) {
    $("#attachmentDiv").dialog({
            close: function () {
                $("#attachmentDiv").empty();
            },
            modal: true,
            height: 800,
            width: 1400,
            open: function () {
                $(this).html('<iframe src="displayattachment.asp?AttachmentGuid=' + sAttachmentGuid + '" style="width:100%; height:100%;" id="attachmentIframe"></iframe>');
            }
        });
        return false;
    }

接着:

<div style="width:100%; height:100%; overflow: hidden;" id="attachmentDiv" title=""></div>

我想要做的是:如果文件(例如图片或pdf)显示在对话框中,一切都很好。如果要下载文件(就像我的 IE 10 对 pdf 文件和所有浏览器对 word/excel 文件所做的那样),对话框应该立即再次关闭,或者甚至可能根本不显示(我认为这是不可能的)。

我在 iframe 上尝试了 onLoad 处理程序,但在 IE 中没有触发。我也尝试过访问$("#attachmentIframe").contents()手动访问(使用控制台)以查看文件是否已嵌入,但这给了我在 firefox 中的错误

Error: Permission denied to access property 'document'

有谁知道检查文件是否由浏览器(或插件)显示或只是下载的任何方法?

4

0 回答 0