JS判断客服QQ号在线还是离线状态的方法

不知道从什么时候开始,原来QQ官方自带的在线离线状态的代码已经不能准确显示在线或离线状态了,现在自己用JS判断QQ在线离线状态值,根据状态值输出在线图片还是离线图片。 

复制代码 代码如下:

<script src="https://www.jb51.net/JS/jquery-1.5.1.min.js"></script> 

<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 客服一</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 客服二</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 客服三</div> 

<script> 
    var online = new Array(); 
</script> 
<script type= "text/javascript" src="http://webpresence.qq.com/getonline?Type=1&111111:222222:333333:" ></script> 
<script type="text/javascript"> 
    for (var i = 0; i < online.length; i++) { 
        if (online[i] == 0) { 
            $(".kfli img").eq(i).attr("src","/onlinekf/offline.gif"); 
        } else { 
            $(".kfli img").eq(i).attr("src",'https://www.jb51.net/onlinekf/online.gif'); 
        } 
    } 
</script>

这是主要判断客服是否在线的程序,自己再添加想要的效果吧。以下是我的小代码:

复制代码 代码如下:

<script src="https://www.jb51.net/JS/jquery-1.5.1.min.js"></script> 
 
<style> 
#divMenu {position:fixed;top:220px;right:0px;_position:absolute; _top: cursor:pointer; display:none} 
#rightad {position:fixed;top:190px;right:7px;width:95px;height:180px;_position:absolute; font-size:12px;} 
#scrollto {position:fixed;bottom:100px; width:30px;right:0px;background:#368bcc;color:#FFF;cursor:pointer; text-align:center;_position:absolute;  display:none} 
.kfli {height:30px; line-height:30px; color:#FFF; text-align:center;cursor:pointer; border-bottom:1px solid #fff} 
#leftad span,#rightad span{cursor:pointer;} 
</style> 
 
<div><img src="https://www.jb51.net/onlinekf/onlinerkf.png" alt="在线咨询"></div>  
<div> 
<span>关闭</span> 
<div> 
<div> 
<div></div> 
 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 客服一</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 客服二</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 客服三</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 市场一</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 市场二</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 市场三</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 市场四</div> 
<div><img src="https://www.jb51.net/onlinekf/online.gif" /> 市场五</div> 
</div> 
</div> 
 
</div> 
<script> 
    var online = new Array(); 
</script> 
<script type= "text/javascript" src="http://webpresence.qq.com/getonline?Type=1&1844565410:363576965:2193744200:1315797152:1609979008:2690151979:3130711794:2825956442:" ></script> 
<script type="text/javascript"> 
    for (var i = 0; i < online.length; i++) { 
        if (online[i] == 0) { 
            $(".kfli img").eq(i).attr("src","/onlinekf/offline.gif"); 
        } else { 
            $(".kfli img").eq(i).attr("src",'https://www.jb51.net/onlinekf/online.gif'); 
        } 
    } 
    
   //关闭浮动 
    $(document).ready(function () { 
        $("#rightad span").click(function () { 
            $("#rightad").hide(300); 
            $("#divMenu").show(300); 
        }); 
 
        $("#divMenu").click(function () { 
            $("#rightad").slideDown(300); 
            $("#divMenu").hide(200); 
        }); 
 
        /* 
        $("#rightad").mouseleave(function(){ 
        $("#rightad").hide(200); 
        $("#divMenu").show(300); 
        }); 
        */ 
    }); 
 
    window.onscroll = function () { 
        if (document.documentElement.scrollTop + document.body.scrollTop > 100) { 
            document.getElementById("scrollto").style.display = "block"; 
        } 
        else { 
            document.getElementById("scrollto").style.display = "none"; 
        } 
    } 
    function OpenSmallWindows(strURL, scrollbar, width, height, left, top) { 
        window.open(strURL, "_blank", 
     "status=no,resizable=0,toolbar=no,menubar=no,scrollbars=" + scrollbar + ",width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ""); 
    } 
    function openQQ(qq) { 
        window.location.href = "tencent://message/?uin=" + qq + "&Site=gbgjs.com&Menu=yes"; 
    } 
</script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxzyz.html