使用 iframe 实现 web 的推送技术

PushPage1.aspx

 

js 如下:

 


 

function Change(str){
    window.document.getElementById("div1").innerText=str;
}


function on_load(){

    var ifrpush = new ActiveXObject("htmlfile");
    ifrpush.open();
    var ifrDiv = ifrpush.createElement("div");
    ifrpush.appendChild(ifrDiv);
    ifrpush.parentWindow.Change=Change;
    ifrDiv.innerHTML = "<iframe src='PushPage2.aspx'></iframe>";
    ifrpush.close();
}


window.onload=on_load;

 

Body 如下:


<div id="div1"></div>

 

 

PushPage2.aspx

 

PushPage2.aspx.cs 如下


protected override void Render(HtmlTextWriter output)
{
            string str;
            while (true)
            {
                str = "<script>window.parent.Change('" + DateTime.Now.ToLongTimeString() + "')</script>";
                this.Context.Response.Write(str);
                this.Context.Response.Flush();
                System.Threading.Thread.Sleep(1000);
            }
}

 

最后运行 PushPage1.aspx 可看到效果。

posted @ 2010-06-08 10:37  踏歌长行  阅读(459)  评论(0编辑  收藏  举报