關鍵字: 提示框 樣本 彈出框
JS檔案內容 Java代碼
- //定義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","message.do?cmd=get",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);
//定義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","message.do?cmd=get",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);
請求的XML內容 Java代碼
- <?xml version="1.0" encoding="UTF-8"?>
- <messages>
- <message>
- <id>001</id>
- <title>通知你今天來開會</title>
- </message>
- </messages>
<?xml version="1.0" encoding="UTF-8"?><messages><message><id>001</id><title>通知你今天來開會</title></message></messages>
如果XML要動態產生則用下面代碼 Java代碼
- <%@ page import="java.util.List,com.sunflower.model.Message" contentType="text/xml;charset=utf-8"%>
- <%
- response.setContentType("text/xml");
- response.setHeader("Cache-Control", "no-cache");
- List list = (List)request.getAttribute("messages");
-
- out.println("<messages>");
- if(list!=null)
- for(int i=0;i<list.size();i++){
- Message objM = (Message)list.get(i);
- out.println("<message>");
- out.println("<id>"+objM.getId()+"</id>");
- out.println("<title>"+objM.getTitle()+"</title>");
- out.println("</message>");
- }
- out.println("</messages>");
- %>
<%@ page import="java.util.List,com.sunflower.model.Message" contentType="text/xml;charset=utf-8"%><%response.setContentType("text/xml");response.setHeader("Cache-Control", "no-cache");List list = (List)request.getAttribute("messages");out.println("<messages>");if(list!=null)for(int i=0;i<list.size();i++){Message objM = (Message)list.get(i);out.println("<message>");out.println("<id>"+objM.getId()+"</id>");out.println("<title>"+objM.getTitle()+"</title>");out.println("</message>");}out.println("</messages>"); %>
HTML檔案內容 Java代碼
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>右下角彈出提示</title>
- </head>
- <script type="text/javascript" src="ajax.js"></script>
- <body>
- <input type="button" onclick="createXMLHttpRequest()" value="測試請求" />
- <div id="contain"></div>
- </body>
- </html>
原帖地址:http://jinghua.javaeye.com/blog/114323