我想做一个消息提醒功能。请大家提供我一些思路。如果做这样一个系统。每次登陆的时候好说,弹出一个页面显示最新消息。如何做到即时提醒那!!即时提醒会不会很消耗资源。还有谁有有像QQ那样的在窗体右下角弹出的消息的代码!

解决方案 »

  1.   

    即使提醒可以用AJAX 或者是 server PUSH   各有利弊   不过建议你先用AJAX
      

  2.   

    如非迫不得已,放弃即时要求session,cookie记录一个时间,用处在后面当页面刷新的时候,判断当前时间,跟上次时间差,,符合条件,则去查询有没有新消息如果页面停留
    定时ajax请求,先判断cookie记录的时间,符合条件了,再发送请求,同时保存时间到cookie服务端的session时间也比对下,
    页面消息提示,div+js就是,可以找个地方,把相应的css copy来,参考
      

  3.   

    网页上一般都用ajax获取
    ajax也有两种方式
    1.轮询:每隔一个时间段向服务器进行请求
    2.长连接:js一直连接到服务器页面,知道服务器有返回的时候js执行才结束
      

  4.   

    右下角弹出框代码<!--дӵhead--><head>
    <SCRIPT language=javascript>
    //more javascript from http://www.kejiweb.com
    window.onload = enetgetMsg;
    window.onresize = enetresizeDiv;
    window.onerror = function(){}
    var enetdivTop,enetdivLeft,enetdivWidth,enetdivHeight,enetdocHeight,enetdocWidth,enetobjTimer,i = 0;
    function enetgetMsg()
    {
    try{
    enetdivTop = parseInt(document.getElementById("enetMeng").style.top,10)
    enetdivLeft = parseInt(document.getElementById("enetMeng").style.left,10)
    enetdivHeight = parseInt(document.getElementById("enetMeng").offsetHeight,10)
    enetdivWidth = parseInt(document.getElementById("enetMeng").offsetWidth,10)
    enetdocWidth = document.body.clientWidth;
    enetdocHeight = document.body.clientHeight;
    document.getElementById("enetMeng").style.top = parseInt(document.body.scrollTop,10) + enetdocHeight + 10;// enetdivHeight
    document.getElementById("enetMeng").style.left = parseInt(document.body.scrollLeft,10) + enetdocWidth - enetdivWidth
    document.getElementById("enetMeng").style.visibility="visible"
    enetobjTimer = window.setInterval("enetmoveDiv()",10)
    }
    catch(e){}
    }function enetresizeDiv()
    {
    i+=1
    if(i>600) enetcloseDiv()
    try{
    enetdivHeight = parseInt(document.getElementById("enetMeng").offsetHeight,10)
    enetdivWidth = parseInt(document.getElementById("enetMeng").offsetWidth,10)
    enetdocWidth = document.body.clientWidth;
    enetdocHeight = document.body.clientHeight;
    document.getElementById("enetMeng").style.top = enetdocHeight - enetdivHeight + parseInt(document.body.scrollTop,10)
    document.getElementById("enetMeng").style.left = enetdocWidth - enetdivWidth + parseInt(document.body.scrollLeft,10)
    }
    catch(e){}
    }
    function enetmoveDiv()
    {
    try
    {
    if(parseInt(document.getElementById("enetMeng").style.top,10) <= (enetdocHeight - enetdivHeight + parseInt(document.body.scrollTop,10)))
    {
    window.clearInterval(enetobjTimer)
    enetobjTimer = window.setInterval("enetresizeDiv()",1)
    }
    enetdivTop = parseInt(document.getElementById("enetMeng").style.top,10)
    document.getElementById("enetMeng").style.top = enetdivTop - 1
    }
    catch(e){}
    }
    function enetcloseDiv()
    {
    document.getElementById('enetMeng').style.visibility='hidden';
    if(enetobjTimer) window.clearInterval(enetobjTimer)
    }
    </SCRIPT>
    <!--дӵBODY--><DIV id=enetMeng
    style="BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; VISIBILITY: visible; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: 241px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: -200px; HEIGHT: 157px">
    <TABLE WIDTH=255 BORDER=0 CELLPADDING=0 CELLSPACING=0 bgcolor="#DAE6FC">
    <TR>
    <TD height="30" valign="top" background="qqimages/heihei_1.jpg">
    <table width="255" height="19" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="212" valign="bottom"><strong><font size="2"><font color="#FF6600">Ϣ</font></font></strong></td>
    <td width="43" style="cursor:hand" onClick="enetcloseDiv()">X</td>
    </tr>
    </table> </TD>
    </TR>
    <TR>
    <TD height="122" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="1">
    <tr>
    <td width="95%"><table align="left" width="98%"><tr><td>
    ӭhttp://www.kejiweb.com</td><tr></table></td>
    </tr>
    </table> </TD>
    </TR>
    <TR>
    <TD></TD>
    </TR>
    </TABLE></div>
      

  5.   

    用AJAX,先记录本次的消息总记录数,再拿总数和实时读取总记录数判断,如果实时读取记录大于上次的总记录就弹!