现在做了一个网站,但是有一个功能一直困扰着我。我想做的就是:当一个用户发送信息给另一个用户时,系统判断收信用户是否在线 —— 如果在线,就像QQ新闻那样在右下角弹出一个小窗口提示收信。 这个功能怎么做的呢?小菜请教各位大虾。

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>弹出提示框</title>
    <style type="text/css">
    #eMeng1{
    border-right: #455690 1px solid;
    border-top: #a6b4cf 1px solid; 
    z-index:99999; 
    left: 0px;
    visibility: hidden; 
    border-left: #a6b4cf 1px solid;
    border-bottom: #455690 1px solid; 
    position: absolute;
    top: 0px;
    width: 250px;
    height: 100px; 
    background-color: #c9d3f3
    }
    .style1{
    border-top: #ffffff 1px solid;
    border-left: #ffffff 1px solid;
    }
    .style2{
    font-size: 12px; 
    background-image: url('msgtopbg.gif'); 
    color: #0f2c8c;
    }
    .style3{
    font-weight: normal;
    font-size: 12px;
    background-image: url('msgtopbg.gif');
    color: #ffffff;
    padding-left: 4px; 
    padding-top: 4px;
    }
    .style4{
    background-image: url('msgtopbg.gif');
    padding-right: 2px;
    padding-top: 2px;
    }
    .style5{
    cursor: hand;
    color:white;
    font-size:12px;
    font-weight:bold;
    margin-right:4px;
    }
    .style6{
    background-image: url('http://pic.tianyaclub.com/images/windty_bg.jpg');
    padding-right: 1px;
    padding-bottom: 1px;
    }
    .style7{
    border-right: #b9c9ef 1px solid;
    padding-right: 13px;
    border-top: #728eb8 1px solid;
    padding-left: 13px;
    font-size: 12px;
    padding-bottom: 13px; 
    border-left: #728eb8 1px solid;
    width: 100%;
    color: #1f336b;
    padding-top: 18px;
    border-bottom: #b9c9ef 1px solid;
    height: 100%
    }
    </style>
    </head>
    <Script language="JavaScript">
    <!--var divid = "eMeng1";window.onload = getMsg;
    window.onresize = resizeDiv;
    window.onerror = function(){}
    //短信提示使用(asilas添加)
    var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
    function getMsg()
    {
        try{
        divTop = parseInt(document.getElementById(divid).style.top,10)
        divLeft = parseInt(document.getElementById(divid).style.left,10)
        divHeight = parseInt(document.getElementById(divid).offsetHeight,10)
        divWidth = parseInt(document.getElementById(divid).offsetWidth,10)
        docWidth = document.body.clientWidth;
        docHeight = document.body.clientHeight;
        document.getElementById(divid).style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight
        document.getElementById(divid).style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth
        document.getElementById(divid).style.visibility="visible"
        objTimer = window.setInterval("moveDiv()",10)
        }
        catch(e){}
    }function resizeDiv()
    {
        i+=1
        //if(i>300) closeDiv()    //客户想不用自动消失由用户来自己关闭所以屏蔽这句
        try{
        divHeight = parseInt(document.getElementById(divid).offsetHeight,10)
        divWidth = parseInt(document.getElementById(divid).offsetWidth,10)
        docWidth = document.body.clientWidth;
        docHeight = document.body.clientHeight;
        document.getElementById(divid).style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10)
        document.getElementById(divid).style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10)
        }
        catch(e){}
    }function moveDiv()
    {
        try
        {
        if(parseInt(document.getElementById(divid).style.top,10) <= (docHeight - divHeight + parseInt
    (document.body.scrollTop,10)))
        {
        window.clearInterval(objTimer)
        objTimer = window.setInterval("resizeDiv()",1)
        }
        divTop = parseInt(document.getElementById(divid).style.top,10)
        document.getElementById(divid).style.top = divTop - 1
        }
        catch(e){}
    }
    function closeDiv()
    {
        document.getElementById(divid).style.visibility='hidden';
        if(objTimer) window.clearInterval(objTimer)
    }
    -->
    </Script>
    <!--温馨提示代码开始-->
    <div id="eMeng1">
        <table class="style1" cellspacing=0 cellpadding=0 width="100%" 
    bgcolor=#afdcf3 border=0>
        <tbody>
            <tr bgcolor=#6699cc>
                <td class="style2" width=30 height=24></td>
                <td class="style3" valign=center width="100%"> 网站温馨提示:</td>
                <td class="style4" valign=center align=right width=19>
       <span title=关闭 class="style5" onclick=closeDiv() >×</span>
       <!--<img title=关闭 style="cursor: hand" onclick=closeDiv() hspace=3 src="msgclose.jpg">-->
       </td>
            </tr>
            <tr>
                <td class="style6" colspan=3 height=90>
                    <div class="style7">生活百科网,你看了吗?<br>
                    <div align=center style="word-break:break-all">
         <a href="http://www.bk163.net" target="_blank">
         <font color=#ff0000>进入网站浏览</font>
         </a>
        </div>
                    </div>
                </td>
            </tr>
        </tbody>
        </table>
    </div>
    <p>
    <!--温馨提示代码结束-->
    </p>
    </html>
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/thymetiantian/archive/2009/07/31/4397776.aspx
      

  2.   

    收信用户---监听数据库有没有新信息----有?弹出:继续监听监听:刷新网页或者AJAX不断去查询有没有信息。
      

  3.   

    网页根本是没状态的
    除非你用ajax定时查看是否有用户给你发送信息了
      

  4.   

    sleep---search----sleep----search------...
      

  5.   

    用多线程监听  用ajax实现调用
      

  6.   

    使用ajax去web服务器监视是否有数据,因为http是无状态的,,
    (个人总结)
    所谓无状态是指:
    以前在写c/s程序的时候用socket编程的时候使用的底层的tcp/ip协议这个东西是有状态的,例如远程教学等等。
    而http是无状态的因为当浏览器请求一次web服务器的时候服务器处理完以后他们之间就没有任何关系想具体了解请发我邮箱[email protected]
      

  7.   

    B/S和C/S不一样,BS是无状态回话,也就是说,当客户机器请求页面时候,服务器就把编译好了的网页返回给客户端,然后他们就断开连接了。如果你要做实时刷新功能,只能用AJAX,异步请求服务器,查看是否有信息。
      

  8.   

    <script src="Js/jquery-1.3.1.js" type="text/javascript"></script>
      <script src="Js/Message.js" type="text/javascript"></script>
      <script  type="text/javascript">
      function GetMessage()
      {
      $.ajax({
                type: "POST",
                url: "TradersData/GetMessage.aspx",
                data: "",
                //出错处理
                error: function() {
                    alert("网络出现故障!请重试!");
                },
                //发送前事件
                beforeSend: function() {
                },
                //成功后事件
                success: function(data) {
                            
                            if(data!=null&&data!="")
                            {
                            $.messager.lays(350, 300);
                            $.messager.show('<font color=red>炼金术财富终端提示</font>', '<font color=green style="font-size:12px; text-align:left;">'+unescape(data)+'</font>');
                            }
                      }
            });
      }
    function SendTradersRoData()
    {
    window.setInterval("GetMessage();", 30000);//设定30秒调用一次}
    </script> 
        
    </head>
    <body onload="SendTradersRoData();">
      

  9.   

    Message.JS 代码(function (jQuery){
    /*
     * jQuery Plugin - Messager
     * Author: corrie Mail: [email protected] Homepage: www.corrie.net.cn
     * Copyright (c) 2008 corrie.net.cn
     * @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
     *
     * $Date: 2008-08-30 
     * $Vesion: 1.1
     @ how to use and example: Please Open demo.html
     */
    this.version = '@1.1';
    this.layer = {'width' : 200, 'height': 100};
    this.title = '信息提示';
    this.time = 114000;
    this.anims = {'type' : 'slide', 'speed' : 600};

    this.inits = function(title, text){
    if($("#message").is("div")){ return; }
    $(document.body).prepend('<div id="message" style="border:#b9c9ef 1px solid;z-index:100;width:'+this.layer.width+'px;height:'+this.layer.height+'px;position:absolute; display:none;background:#cfdef4; bottom:0; right:0; overflow:hidden;"><div style="border:1px solid #fff;border-bottom:none;width:100%;height:25px;font-size:12px;overflow:hidden;color:#1f336b;"><span id="message_close" style="float:right;padding:5px 0 5px 0;width:16px;line-height:auto;color:red;font-size:12px;font-weight:bold;text-align:center;cursor:pointer;overflow:hidden;">×</span><div style="padding:5px 0 5px 5px;width:100px;line-height:18px;text-align:left;overflow:hidden;">'+title+'</div><div style="clear:both;"></div></div> <div style="padding-bottom:5px;border:1px solid #fff;border-top:none;width:100%;height:auto;font-size:12px;"><div id="message_content" style="margin:0 5px 0 5px;border:#b9c9ef 1px solid;padding:10px 0 10px 5px;font-size:12px;width:'+(this.layer.width-17)+'px;height:'+(this.layer.height-50)+'px;color:#1f336b;text-align:left;overflow:hidden;">'+text+'</div></div></div>');
    };
    this.show = function(title, text, time){
    if($("#message").is("div")){ return; }
    if(title==0 || !title)title = this.title;
    this.inits(title, text);
    if(time)this.time = time;
    switch(this.anims.type){
    case 'slide':$("#message").slideDown(this.anims.speed);break;
    case 'fade':$("#message").fadeIn(this.anims.speed);break;
    case 'show':$("#message").show(this.anims.speed);break;
    default:$("#message").slideDown(this.anims.speed);break;
    }
    $("#message_close").click(function(){
    setTimeout('this.close()', 1);
    });
    //$("#message").slideDown('slow');
    this.rmmessage(this.time);
    };
    this.lays = function(width, height){
    if($("#message").is("div")){ return; }
    if(width!=0 && width)this.layer.width = width;
    if(height!=0 && height)this.layer.height = height;
    }
    this.anim = function(type,speed){
    if($("#message").is("div")){ return; }
    if(type!=0 && type)this.anims.type = type;
    if(speed!=0 && speed){
    switch(speed){
    case 'slow' : ;break;
    case 'fast' : this.anims.speed = 200; break;
    case 'normal' : this.anims.speed = 400; break;
    default:
    this.anims.speed = speed;
    }
    }
    }
    this.rmmessage = function(time){
    setTimeout('this.close()', time);
    //setTimeout('$("#message").remove()', time+1000);
    };
    this.close = function(){
    switch(this.anims.type){
    case 'slide':$("#message").slideUp(this.anims.speed);break;
    case 'fade':$("#message").fadeOut(this.anims.speed);break;
    case 'show':$("#message").hide(this.anims.speed);break;
    default:$("#message").slideUp(this.anims.speed);break;
    };
    setTimeout('$("#message").remove();', this.anims.speed);
    this.original();
    };
    this.original = function(){
    this.layer = {'width' : 200, 'height': 100};
    this.title = '信息提示';
    this.time = 114000;
    this.anims = {'type' : 'slide', 'speed' : 600};
    };
        jQuery.messager = this;
        return jQuery;
    })(jQuery);
      

  10.   

    没做过,好像在netcms里边有,你可以去看看,怎么实现的没有具体研究过。
    帮你顶帖吧