Posted in Javascript onJanuary 13, 2015
本文实例讲述了JS判断客服QQ号在线还是离线状态的方法。分享给大家供大家参考。具体分析如下:
不知道从什么时候开始,原来QQ官方自带的在线离线状态的代码已经不能准确显示在线或离线状态了,现在自己用JS判断QQ在线离线状态值,根据状态值输出在线图片还是离线图片。
<script src="JS/jquery-1.5.1.min.js"></script> <div class="kfli" onclick="openQQ('111111')"><img src="/onlinekf/online.gif" border="0" /> 客服一</div> <div class="kfli" onclick="openQQ('222222')"><img src="/onlinekf/online.gif" border="0" /> 客服二</div> <div class="kfli" onclick="openQQ('333333')"><img src="/onlinekf/online.gif" border="0" /> 客服三</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",'/onlinekf/online.gif'); } } </script>
这是主要判断客服是否在线的程序,自己再添加想要的效果吧。以下是我的小代码:
<script src="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 id="divMenu"><img src="/onlinekf/onlinerkf.png" class="press" alt="在线咨询"></div> <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="/onlinekf/online.gif" border="0" /> 客服一</div> <div class="kfli" onclick="openQQ('222222')"><img src="/onlinekf/online.gif" border="0" /> 客服二</div> <div class="kfli" onclick="openQQ('333333')"><img src="/onlinekf/online.gif" border="0" /> 客服三</div> <div class="kfli" onclick="openQQ('444444')"><img src="/onlinekf/online.gif" border="0" /> 市场一</div> <div class="kfli" onclick="openQQ('555555')"><img src="/onlinekf/online.gif" border="0" /> 市场二</div> <div class="kfli" onclick="openQQ('666666')"><img src="/onlinekf/online.gif" border="0" /> 市场三</div> <div class="kfli" onclick="openQQ('777777')"><img src="/onlinekf/online.gif" border="0" /> 市场四</div> <div class="kfli" onclick="openQQ('888888')"><img src="/onlinekf/online.gif" border="0" /> 市场五</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",'/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>
希望本文所述对大家的javascript程序设计有所帮助。
JS判断客服QQ号在线还是离线状态的方法
- Author -
shichen2014声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@