<html>??
<head>??
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />??
<title>右下角彈出提示</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
?//定義XMLHttp實例??
var xmlHttp;??
function createXMLHttpRequest(){??
//開始初始化XMLHttpRequest對象??
? if(window.ActiveXObject){??
//IE瀏覽器??
??? xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");??
? }else if(window.XMLHttpRequest){??
//Mozilla瀏覽器??
??? xmlHttp = new XMLHttpRequest();??
? }??
if(xmlHttp){??
??? //設置請求地址??
??? xmlHttp.open("GET","/test/prompt.xml",true);??
??? xmlHttp.onreadystatechange=setState;//設置回調函數??
??? xmlHttp.send(null);??
? }??
}??
//回調函數??
function setState(){??
? if(xmlHttp.readyState == 4){??
??? if(xmlHttp.status == 200){??
??????? parseResults(xmlHttp.responseXML)??
??? }??
? }??
}???
/*處理XML*/?
function parseResults(xmlDOM) {??
try{??
var root = xmlDOM.documentElement;???
var info = root.getElementsByTagName('message');??
var out? = "";??
var message = null;??
var current = null;??
?????? for(var i=0;i<info.length;i++){??
??????????? message = info[i];??
??????????????????????? id??? = message.getElementsByTagName("id")[0].firstChild.data;??
??????????????????????? title = message.getElementsByTagName("title")[0].firstChild.data;??
????????????? out=out+(i+1)+"."+"<a style=\"font-size:12px; color: #6D93C8; face: Tahoma\" title='內容提要:\n"?
????????????? +title??
????????????? +"\n時間:"?
????????????? +title??
????????????? +"'"+" href=# >"?
????????????? +title??
????????????? +"</a><BR>";??
?????????? }???
????? popmsg("<BR>"+out);??
? }catch(exception){??
?//???? alert("出錯了!");??
??? }???
}??
?
/*右下角提示框*/?
var oPopup = window.createPopup();??
var popTop=50;??
function popshow(){??
oPopup.show(screen.width-250,screen.height-popTop,241,172);??
}??
function pophide(){??
oPopup.hide();??
}??
function popmsg(msgstr){??
?
??? var winstr="<table? valign=\"top\" style=\"border: 1 solid #6D93C8\" width=\"241\" height=\"172\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >";??
??? winstr+="<tr><td bgcolor=\"#BCCCDF\" onClick=\"parent.pophide();\" valign=\"top\" align=\"center\"? height=\"20\" style=\"font-size:14px; color: #6D93C8; face: Tahoma;filter:Blur(add=1,direction=45,strength=8) \">你有新短消息:</td></tr><tr><td valign=\"top\" align=\"center\"><table valign=\"top\" width=\"90%\" height=\"110\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";??
??? winstr+="<tr><td valign=\"top\" style=\"font-size:12px; color: #6D93C8; face: Tahoma\">"+msgstr+"</td></tr></table></td></tr></table>";??
??????
??? oPopup.document.body.innerHTML = winstr;??
??? popshow();??
??? setInterval('window.focus()',0); //讓IE重獲取焦點???
??????
}??
?
/*提示間隔時間*/?
var secs=5;//第一次提示時間秒??
??? function checkServer(secs){??
??? for(i=1;i<=secs;i++) {??
???? window.setTimeout("update(" + i + ")", i * 1000);??
??? }??
??? }??
??? function update(num) {??
???? if(num == secs) {??
????? createXMLHttpRequest();??
????? secs=1*60;//提示時間秒??
????? for(i=1;i<=secs;i++) {??
???? window.setTimeout("update(" + i + ")", i * 1000);??
??? }??
???? }??
??? else {??
???? printnr = secs-num;??
???? }??
??? }??
checkServer(secs);
//-->
</SCRIPT>
</head>??
<body>??
<input type="button" onclick="createXMLHttpRequest()" value="測試請求" />??
<div id="contain"></div>??
</body>??
</html>
posted on 2008-06-13 20:22
crazy 閱讀(94)
評論(0) 編輯 收藏 所屬分類:
ajax