简体   繁体   English

如何将P3P标头直接添加到iframe?

[英]How do I add a P3P header directly onto an iframe?

I am using the AjaxFileUpload control, and in the source code of the AjaxControlToolkit I see that an iframe is used for this control. 我正在使用AjaxFileUpload控件,并且在AjaxControlToolkit的源代码中看到该控件使用了iframe。 On my own website I have the P3P header in my web.config, but the script that uses the iframe is from the AjaxControlToolkit.dll. 在我自己的网站上,我的web.config中有P3P标头,但是使用iframe的脚本来自AjaxControlToolkit.dll。 Below is a snippet from the source code for the toolkit. 以下是该工具包的源代码片段。 What can I add to it to get it to send this P3P header? 我可以添加什么使其发送此P3P标头? ie8/10 are blocking a handler from the toolkit. ie8 / 10正在阻止工具箱中的处理程序。

EDIT: The fix is to comment out iframe.security = "restricted"; 编辑:解决方法是注释掉iframe.security =“ restricted”; I updated the code below. 我更新了下面的代码。

    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;
        }
    } 
};

The fix for this was to remove one little line: 解决此问题的方法是删除一行:

iframe.security = "restricted";

Keeping that line in there makes ie treat the iframe with the same level of security as a site in the user's "Restricted" list. 保持该行不变,即使iframe的安全级别与用户的“受限制”列表中的站点相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM