本文实例讲述了JS判断客服QQ号在线还是离线状态的方法。分享给大家供大家参考。具体分析如下:

不知道从什么时候开始,原来QQ官方自带的在线离线状态的代码已经不能准确显示在线或离线状态了,现在自己用JS判断QQ在线离线状态值,根据状态值输出在线图片还是离线图片。 
复制代码 代码如下:<script src="/UploadFiles/2021-04-02/jquery-1.5.1.min.js">

<div class="kfli" onclick="openQQ('111111')"><img src="/onlinekf/online.gif"> <div class="kfli" onclick="openQQ('222222')"><img src="/UploadFiles/2021-04-02/online.gif"> <div class="kfli" onclick="openQQ('333333')"><img src="/onlinekf/online.gif">

<script> 
    var online = new Array(); 
</script> 
<script type= "text/javascript" src="/UploadFiles/2021-04-02/getonline"> <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",'/onlinekf/online.gif'); 
        } 
    } 
</script>

这是主要判断客服是否在线的程序,自己再添加想要的效果吧。以下是我的小代码:
复制代码 代码如下:<script src="/UploadFiles/2021-04-02/jquery-1.5.1.min.js">  
<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 id="divMenu"><img src="/UploadFiles/2021-04-02/onlinerkf.png"> <div id="rightad"> 
<span style="color:#0f8ed2">关闭</span> 
<div style="height:351px; background:url(/onlinekf/onkf.jpg) #368bcc; background-position:center top; background-repeat:no-repeat;width:91px"> 
<div style="height:90px; width:91px"> 
<div style="width:91px; height:91px; cursor:pointer"></div> 
 
<div class="kfli" onclick="openQQ('111111')"><img src="/UploadFiles/2021-04-02/online.gif"> <div class="kfli" onclick="openQQ('222222')"><img src="/onlinekf/online.gif"> <div class="kfli" onclick="openQQ('333333')"><img src="/UploadFiles/2021-04-02/online.gif"> <div class="kfli" onclick="openQQ('444444')"><img src="/onlinekf/online.gif"> <div class="kfli" onclick="openQQ('555555')"><img src="/UploadFiles/2021-04-02/online.gif"> <div class="kfli" onclick="openQQ('666666')"><img src="/onlinekf/online.gif"> <div class="kfli" onclick="openQQ('777777')"><img src="/UploadFiles/2021-04-02/online.gif"> <div class="kfli" onclick="openQQ('888888')"><img src="/onlinekf/online.gif"> </div> 
</div> 
 
</div> 
<script> 
    var online = new Array(); 
</script> 
<script type= "text/javascript" src="/UploadFiles/2021-04-02/getonline"> <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",'/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/" + qq + "&Site=gbgjs.com&Menu=yes"; 
    } 
</script>

希望本文所述对大家的javascript程序设计有所帮助。

标签:
JS,判断,客服,QQ,在线,离线,状态,方法

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com