隐藏iframe chrome回调未触发

Hidden iframe chrome callback not fired

本文关键字:回调 iframe chrome 隐藏      更新时间:2023-09-26

我正在开发一个使用隐藏框架技术从服务器检索一些数据的网页。数据是实时更新的,服务器在每次修改时通知浏览器。

该组件在IE和Firefox中都可以工作,但在chrome中,服务器检索的回调函数不会在客户端浏览器中执行。但是,我可以看到在开发人员工具中打开了连接,并且通过该连接接收到的数据正在增长。

我读到一些浏览器可能在解析和执行从服务器接收的数据时出现问题,但我无法找到解决这些情况的方法。

也许我需要发送一些http头到这种情况下,但我甚至不知道搜索什么。

编辑:代码示例这是我用来连接到服务器的函数。它是在步进符号之后调用的。登录的实现方式与连接步骤相同。
function __sendConnectRequest()
{
    document.getElementById(UID).setAttribute('value', __username);  
    document.getElementById(SID).setAttribute('value', __sessionKey);
    document.getElementById(PID).setAttribute('value', __privateKey);
    try
    {
        document.getElementById('connectFormId').submit();  
    }
    catch (err)
    {
        alert("error connecting");
        console.log("__sendConnectRequest: " + err.message);
    }    
}

var __connectResponseCallback = null;
function __setConnectResponseCallback(callback)
{
    __connectResponseCallback = callback;
}
function __connectResponseHandler(statusCode)
{
     if(__connectResponseCallback)
     {
        __connectResponseCallback(statusCode);       
     }
}

这就是我如何创建我的DOM元素。这些元素被附加到文档的主体,并且表单有一些输入字符串。

function getNewIframe(name, id)
{
    //KNOWN BUG IN IE while creating iframes
    //http://webbugtrack.blogspot.com/2007/10/bug-235-createelement-is-broken-in-ie.html
    var iframe;
    try
    {
        iframe = document.createElement('<iframe name="' + name + '">');
    }
    catch (ex)
    {
        iframe = document.createElement('iframe');
        iframe.name = name;
    }
    iframe.id = id;
    iframe.style.display = 'none';
    return iframe;
}    
function getNewForm(name, id, target, action)
{
    var form = document.createElement("form");
    form.name = name;
    form.id = id;
    form.method = 'post';
    form.target = target;
    form.action = serverUrl+action; 
    form.style.display = 'none';
    return form;
}    

通过在服务器响应中添加multipart/x-mixed-replace标头来解决该问题。这样,数据以块的形式执行,浏览器不需要等待接收到所有的响应。

这似乎是彗星技术的老标准。