最近我的工程中有一个需求,在页面右下角弹出一个提示窗。具体需求例如:一个用户登陆系统主页,他有一些未读的通知,在他登陆时到刷新页面之间这段时间如果刚好又有一个通知发给了他,在页面上是看不到的,所以想搞一个类似QQ有人上线时的提示窗。现在还没有思路,不知该用什么技术实现,希望高手赐教,能把解决问题的思路和所用的技术介绍清楚一点最好,如果有列子就更好了,谢谢!

解决方案 »

  1.   

    和csdn上的也差不多吧
    我还真没试过
      

  2.   


    用AJAX实现+定时器
    var req;
    function executeXhr(callback, url) {
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
        req.onreadystatechange = callback;
        req.open("GET", url, false);
        req.send(null);
    }else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
       if (req) {
            req.onreadystatechange = callback;
            req.open("GET", url, false);
            req.send();
        }
    }
    }   
    function processAjaxResponse() {
        var tmStr="";
        //alert(req.readyState);
    if (req.readyState == 4) {
        if (req.status == 200) {
            tmStr=req.responseText.split("@");        
            var msgCount = parseInt(tmStr[0]);
            if(!isNaN(msgCount)){
            if("0" != tmStr[0]){
            var msgCon = "您有"+ tmStr[0]+"条新消息";
            var MSG1 = new messageTip("aa",300,200,"消息提示:",msgCon,tmStr[1]);  
        MSG1.rect(null,null,null,screen.height-50); 
        MSG1.speed    = 10; 
        MSG1.step    = 5; 
        MSG1.show();  
            }else{
            }       
            }
           
        } else {
        }
    }
    }
    var timer;
      function submitForm(){
        var url = "../message/messageprompt.do?source=all";
    var callback = processAjaxResponse;
    try{
    executeXhr(callback, url);
    //timer = setTimeout(submitForm,300000);
    timer = setTimeout(submitForm,50000);

    }catch(Exception){
    clearTimeout(timer);
    //alert("服务器已停止!");
    }
      }