定时弹出层

来源:互联网 发布:hishop云商城2.0源码 编辑:程序博客网 时间:2024/05/01 10:05

这里主要用到HttpModule  然后再结合客户端定时弹出层。


 public void Init(HttpApplication context)        {           // context.BeginRequest += new EventHandler(context_BeginRequest);            context.EndRequest += new EventHandler(context_EndRequest);        }        void context_EndRequest(object sender, EventArgs e)        {               HttpApplication ha = (HttpApplication)sender;               DateTime starTime = new DateTime(2014, 7, 1, 17, 40, 59);               DateTime endTime = new DateTime(2014, 7, 1, 17, 42, 0);               var obj = Tuple.Create(starTime, endTime);               if (DateTime.Now > endTime) return;               TimeSpan ts = starTime - DateTime.Now;               TimeSpan endTs = endTime - DateTime.Now;               System.Text.StringBuilder sb = new StringBuilder();               sb.Append("<script> ");               sb.Append("var div_box = document.createElement('DIV');");               sb.Append(" div_box.id = 'box';");               sb.Append("div_box.style.display = 'none';");               sb.Append("div_box.innerHTML = 'test';");               sb.Append("document.body.appendChild(div_box);");                    sb.AppendFormat("var StartVal={0};", ts.TotalSeconds);               sb.AppendFormat("var EndVal={0};", endTs.TotalSeconds);               sb.Append("var timeID=setInterval(TimeOut,1000); ");               sb.Append("function TimeOut() { ");               sb.Append("if(EndVal<0){document.getElementById('box').style.display='none';window.clearInterval(timeID);}\n");               sb.Append("else{");               sb.Append("if(StartVal>0) {");               sb.Append("document.getElementById('box').style.display='none';}");               sb.Append("else{");               sb.Append("document.getElementById('box').style.display='';");               sb.Append("}");               sb.Append("}");               sb.Append("StartVal--;EndVal--;");               sb.Append("}");               sb.Append("</script>");               ha.Response.Write(sb.ToString());        }

0 0