服务器代码:
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);
}
上面的代码写在一个HttpHandler中当客户端关闭时,服务器并不知道或是没有马上知道,于是向浏览器继续推送。
当执行<script >window.parent.Change('" + DateTime.Now.ToLongTimeString() + "')</script>时
由于找不到Change()方法浏览器提示JS错误。请问如果在浏览器关闭窗口时能通知到服务器 中止死循环。
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);
}
上面的代码写在一个HttpHandler中当客户端关闭时,服务器并不知道或是没有马上知道,于是向浏览器继续推送。
当执行<script >window.parent.Change('" + DateTime.Now.ToLongTimeString() + "')</script>时
由于找不到Change()方法浏览器提示JS错误。请问如果在浏览器关闭窗口时能通知到服务器 中止死循环。
这样即使关闭了浏览器 刚才的连接也会在60秒后自动放弃