如何直接在iframe上添加P3P标头?

时间:2014-12-15 16:25:52

标签: javascript asp.net ajax internet-explorer iframe

我正在使用AjaxFileUpload控件,在AjaxControlToolkit的源代码中,我看到iframe用于此控件。在我自己的网站上,我的web.config中有P3P标题,但使用iframe的脚本来自AjaxControlToolkit.dll。以下是工具包源代码的片段。我可以添加什么来让它发送这个P3P标头? ie8 / 10阻止了工具包中的处理程序。

编辑:修复是注释掉iframe.security ="限制&#34 ;;我更新了以下代码。

    this.createIFrame = function() {

    var name = this._iframeName,
        iframe = document.createElement("IFRAME");

    iframe.width = "0";
    iframe.height = "0";
    iframe.style.display = "none";
    iframe.src = "about:blank";
    //iframe.src = "javascript:'<script>window.onload=function(){document.write(\\'<script>document.domain=\\\"" + document.domain + "\\\";<\\\\/script>\\');document.close();};<\/script>'";
    iframe.id = name;
    iframe.name = name;
    //iframe.security = "restricted";
    document.body.appendChild(iframe);
    iframe.contentWindow.name = name;
    $addHandlers(iframe, {
        load: Function.createDelegate(this, this.onIFrameLoadedHandler)
    });

    this._iframe = iframe;
};

this.onIFrameLoadedHandler = function (e) {
    /// <summary>
    /// Event handler to capture when iframe receive response from server.
    /// </summary>
    /// <param name="e"></param>

    if (!control._currentFileId)
        return;

    try {

        var iframe = this._iframe, doc = null;

        // Only test the iframe data, exception should thrown if something went wrong.
        if (iframe.contentDocument)
            // Firefox, Opera
            doc = iframe.contentDocument;
        else if (iframe.contentWindow)
            // Internet Explorer
            doc = iframe.contentWindow.document;
        else if (iframe.document)
            // Others?
            doc = iframe.document;

        if (doc == null)
            throw "Document not initialized";

        // finalizing and upload next file
        control.doneAndUploadNextFile(control.getCurrentFileItem());

    } catch (e) {

        // Cancelation / aborting upload can causing 'Access is denied' or 'Permission denied' on IE 9 bellow,
        // let's consider this exception is not trully error exception from server.
        if (!control._canceled || !(e.message && (e.message.indexOf("Access is denied") > -1 || e.message.indexOf("Permission denied") > -1))) {
            this.raiseUploadError(e);
            throw e;
        }
    } 
};

1 个答案:

答案 0 :(得分:0)

解决这个问题的方法是删除一条小行:

iframe.security = "restricted";

将该行保留在那里使ie将iframe视为与用户的“Restricted”列表中的站点具有相同的安全级别。