本文實例講述了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程序設計有所幫助。