var timeout = null; //setInterval函數控制代碼
var xmlHttp = false; //
//初始化XMLHttpRequest對象
function createXmlHttp(){
xmlHttp = false;
if (window.ActiveXObject) {
try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
}else if (window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest();}
}
//非同步呼叫頁面擷取結果timestamp為了不讓瀏覽器緩衝結果
function sendRequest(){
createXmlHttp();
var url = "/message/getmessage.asp教程?timestamp=" + new Date().getTime();
if (!xmlHttp) {
alert("XMLHttpRequest is not Create!");
}
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function(){//回呼函數開始
var tag = document.getElementById("newmsg");
tag.innerHTML = "";
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if (xmlHttp.responseText>0) {
tag.innerHTML= "<img src='/images/msg.gif' width='16' height='15' /> 您有[ "+xmlHttp.responseText+" ]封未讀郵件";
}else{
tag.innerHTML="";
}
}
}//回呼函數結束
xmlHttp.send(null);
}
//開始自動重新整理
function update(){
timeout = window.setInterval("sendRequest()", 10000);//設定10秒調用一次update頁面
}
//停止自動重新整理
function Stopupdate(){
if (timeout != null) {
window.clearInterval(timeout);
}
}%>