Web的(Popup)桌面提醒,不错的一个代码,值得收藏(详细代已包括在附件里)

全部代码如下:
1<style id="popupmanager">
2.popup{
3font-size:9pt;
4width: 329px;
5height: 74px;
6border: 1px solid #0A246A;
7filter: Alpha(opacity=80);
8}
9.popup td{
10font-size:9pt;
11}
12.popupCaption{
13background-image: url(images/popup_bg_caption.gif);
14height: 7px;
15}
16.popupCaptionText{
17overflow:hidden;
18width: 260;
19height: 100%;
20padding-right: 4px;
21padding-top: 4px;
22text-decoration: underline;
23color: blue;
24}
25
26.popupBody{
27background-image: url(images/popup_bg_body.gif);
28}
29.popupBodyText{
30overflow:hidden;
31width: 100%;
32height: 100%;
33word-break: break-all;
34word-wrap :break-word;
35line-height: 1.1em;
36padding-top: 1px;
37text-decoration: underline;
38color: blue;
39}
40
41.popupButton{
42
43}
44.popupButtonHover{
45background-color: #0A246A;
46}
47.popupButtonHover TD{
48background-color: #B6BDD2;
49}
50
51.popupMenu{
52width: 177px;
53border: 1px solid #666666;
54background-color: #F9F8F7;
55padding: 1px;
56}
57.popupMenuTable{
58background-image: url(images/popup_bg_menu.gif);
59background-repeat: repeat-y;
60}
61.popupMenuTable TD{
62font-size: 9pt;
63cursor: default;
64}
65.popupMenuRow{
66height: 22px;
67padding: 1px;
68}
69.popupMenuRowHover{
70height: 22px;
71border: 1px solid #0A246A;
72background-color: #B6BDD2;
73}
74.popupMenuSep{
75background-color: #A6A6A6;
76height:1px;
77width: expression(parentElement.offsetWidth-27);
78position: relative;
79left: 28;
80}
81</style>
82<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
83<script language="JavaScript" type="text/javascript">
84
85// 队列
86function Queue()
87{
88var items = new Array();
89
90var first = 0;
91var count = 0;
92
93// 队列大小
94//
95this.Count = function()
96{
97return count;
98} ;
99
100// 取队列头/尾
101//
102this.Peek = function(last)
103{
104var result = null;
105
106if (count > 0)
107{
108if (null != last && true == last)
109result = items[first + (count - 1)];
110else
111result = items[first];
112}
113
114return result;
115};
116
117// 入列
118//
119this.Enqueue = function(x)
120{
121items[first + count] = x;
122
123count++;
124return x;
125};
126
127// 出列
128//
129this.Dequeue = function()
130{
131var result = null;
132
133if (count > 0)
134{
135result = items[first];
136
137delete items[first];
138first++;
139count--;
140}
141
142return result;
143};
144}
145
146
147var newlineRegExp = new RegExp("(\r\n|\n|\r)", "g");
148
149function NewlineReplace(str)
150{
151result = "";
152
153if (str != null)
154result = str.replace(newlineRegExp, "<br>");
155
156return result;
157}
158
159var entityList = new Array();
160entityList["<"] = "<";
161entityList["\uff1c"] = "<";
162entityList[">"] = ">";
163entityList["\uff1e"] = ">";
164entityList["&"] = "&";
165entityList["\uff06"] = "&";
166entityList["\""] = """;
167entityList["\uff02"] = """;
168
169function EntityReplace(str)
170{
171var result = "";
172
173if (str != null)
174{
175var len = str.length;
176
177var i = 0;
178
179while (i < len)
180{
181var j = i;
182
183var e = entityList[str.charAt(j)];
184
185while (j < len && null == e)
186{
187j++;
188
189e = entityList[str.charAt(j)];
190}
191
192result += str.substr(i, j - i);
193
194if (e != null)
195{
196result += e;
197
198j++;
199}
200
201i = j;
202}
203}
204
205return result;
206}
207
208function GetPopupCssText()
209{
210var styles = document.styleSheets;
211var csstext = "";
212for(var i=0; i<styles.length; i++)
213{
214if (styles[i].id == "popupmanager")
215csstext += styles[i].cssText;
216}
217return csstext;
218}
219
220function PopupWin(winID)
221{
222this.Win = document.getElementById(winID);
223this.Menu = document.getElementById(winID + "_Menu");
224this.Icon = document.getElementById(winID + "_Icon");
225this.MenuButton = document.getElementById(winID + "_MenuButton");
226this.CloseButton = document.getElementById(winID + "_CloseButton");
227this.Caption = document.getElementById(winID + "_Caption");
228this.CaptionText = document.getElementById(winID + "_CaptionText");
229this.Body = document.getElementById(winID + "_Body");
230this.BodyText = document.getElementById(winID + "_BodyText");
231}
232
233function Popup(winID, message, icon, title, func)
234{
235this.PostID;
236this.URL;
237this.Type = "Mail"; // Mail,Thread,Post,Message
238this.win = new PopupWin(winID);
239this.popup = null;
240this.popupMenu = null;
241this.PopupManager = null;
242this.showTime = null;
243this.func = func;
244this.isMouseOver = false;
245this.CreateBody = Popup_CreateBody;
246this.Close = Popup_Close;
247this.Hide = Popup_Hide;
248this.Show = Popup_Show;
249this.ShowTime = Popup_ShowTime;
250this.aspxl = this.CreateBody(message, icon, title);
251}
252
253function Popup_Close()
254{
255if (this.popup != null)
256this.popup.document.onmouseover = null;
257else
258this.win.Win.onmouseover = null;
259
260this.isMouseOver = false;
261this.ShowTime = function()
262{
263return 7;
264}
265
266this.Hide();
267}
268
269function Popup_Hide()
270{
271if (this.popup != null && this.popup.isOpen)
272{
273this.popup.hide();
274}
275
276this.popup = null;
277}
278
279function Popup_ShowTime()
280{
281var result = null;
282
283if (this.showTime != null)
284{
285var now = new Date();
286
287result = (now - this.showTime)/1000;
288}
289
290return result;
291}
292
293//
294function OnClickClose_Popup()
295{
296var p = this.getAttribute("popup");
297p.Close();
298}
299
300function OnClickMenu_Popup()
301{
302var p = this.getAttribute("popup");
303if (p.popupMenu == null)
304{
305p.popupMenu = p.popup.document.parentWindow.createPopup();
306var d = p.popupMenu.document;
307var s = d.createStyleSheet();
308s.cssText = GetPopupCssText();
309var b = d.body;
310b.rightmargin = 0;
311b.leftmargin = 0;
312b.topmargin = 0;
313b.bottommargin = 0;
314b.innerHTML = p.win.Menu.outerHTML;
315b.style.cursor = "default";
316b.oncontextmenu = OnContextMenu_Popup;
317b.onmouseover = OnMouseOver_PopupMenu;
318b.onmouseout = OnMouseOut_PopupMenu;
319b.setAttribute("popup", p);
320var menuDisable = d.getElementById(p.win.Win.id + "_Menu_Disable");
321menuDisable.onclick = OnClickDisable_PopupMenu;
322menuDisable.setAttribute("popup", p);
323var menuSetting = d.getElementById(p.win.Win.id + "_Menu_Setting");
324menuSetting.onclick = OnClickSetting_PopupMenu;
325menuSetting.setAttribute("popup", p);
326}
327var toastWidth = p.win.Menu.offsetWidth;
328var toastHeight = p.win.Menu.offsetHeight;
329var toastVerticalMargin = 20;
330var toastHorizontalMargin = 0;
331p.popupMenu.show(toastHorizontalMargin, -toastVerticalMargin-toastHeight,
332toastWidth, toastHeight, p.win.MenuButton);
333}
334
335function OnClick_Popup()
336{
337var p = this.getAttribute("popup");
338
339if (p != null && p.func != null)
340{
341p.func(p);
342}
343}
344
345function OnClickDisable_PopupMenu()
346{
347var p = this.getAttribute("popup");
348
349if (p != null)
350{
351p.PopupManager.Disabled = true;
352p.Close();
353}
354}
355
356function OnClickSetting_PopupMenu()
357{
358var url = this.getAttribute("URL");
359var p = this.getAttribute("popup");
360
361if (url != null)
362{
363window.open(url);
364if (p != null)
365{
366p.Close();
367}
368}
369}
370
371function OnContextMenu_Popup()
372{
373var p = this.getAttribute("popup");
374p.Close();
375}
376
377function OnMouseOver_Popup()
378{
379var p = this.getAttribute("popup");
380p.isMouseOver = true;
381}
382
383function OnMouseOut_Popup()
384{
385var p = this.getAttribute("popup");
386p.isMouseOver = false;
387}
388
389function OnMouseOver_PopupMenu()
390{
391var p = this.getAttribute("popup");
392p.isMouseOver = true;
393}
394
395function OnMouseOut_PopupMenu()
396{
397var p = this.getAttribute("popup");
398p.isMouseOver = false;
399}
400
401function Popup_Show()
402{
403this.showTime = new Date();
404this.popup = window.createPopup();
405var d = this.popup.document;
406
407// d.createStyleSheet("CSS/style.css");
408var s=d.createStyleSheet();
409s.cssText = GetPopupCssText();
410var b = d.body;
411b.rightmargin = 0;
412b.leftmargin = 0;
413b.topmargin = 0;
414b.bottommargin = 0;
415b.innerHTML = this.aspxl;
416b.style.cursor = "default";
417b.oncontextmenu = OnContextMenu_Popup;
418b.onmouseover = OnMouseOver_Popup;
419b.onmouseout = OnMouseOut_Popup;
420b.setAttribute("popup", this);
421var closeButton = d.getElementById(this.win.Win.id + "_CloseButton");
422closeButton.onclick = OnClickClose_Popup;
423closeButton.setAttribute("popup", this);
424
425var menuButton = d.getElementById(this.win.Win.id + "_MenuButton");
426menuButton.onclick = OnClickMenu_Popup;
427menuButton.setAttribute("popup", this);
428
429var popupMessage = d.getElementById(this.win.Win.id + "_BodyText");
430popupMessage.style.cursor = "hand";
431popupMessage.onclick = OnClick_Popup;
432popupMessage.setAttribute("popup", this);
433var toastWidth = this.win.Win.offsetWidth;
434var toastHeight = this.win.Win.offsetHeight;
435var toastVerticalMargin = 28;
436var toastHorizontalMargin = 16;
437var screenWidth = window.screen.width;
438var screenHeight = window.screen.height;
439this.popup.show(screenWidth - toastWidth - toastHorizontalMargin,
440screenHeight - toastHeight - toastVerticalMargin,
441toastWidth, toastHeight);
442
443}
444
445function Popup_CreateBody(msg, icon, title)
446{
447if (icon != null && icon != "")
448this.win.Icon.src = icon;
449this.win.BodyText.innerHTML = NewlineReplace(EntityReplace(msg));;
450this.win.CaptionText.innerHTML = title;
451var win = this.win.Win.cloneNode(true);
452win.style.display = "";
453return win.outerHTML;
454}
455
456
457function PopupManager()
458{
459var queue = new Queue();
460this.Disabled = false;
461
462var canShow = (window.createPopup != null);
463this.Heartbeat = function()
464{
465if (queue.Count() > 0)
466{
467var p = queue.Peek();
468
469var delta = p.ShowTime();
470
471if (delta == null)
472{
473if (!this.Disabled)
474p.Show();
475}
476else if ((p.popup == null) || (!p.popup.isOpen) || (!p.isMouseOver && delta >= 7))
477{
478p.Hide();
479
480queue.Dequeue();
481}
482}
483}
484
485this.AddPopup = function(winid, message, icon, title, func)
486{
487var result = null;
488do
489{
490if (canShow)
491{
492result = new Popup(winid, message, icon, title, func);
493result.PopupManager = this;
494
495queue.Enqueue(result);
496this.Heartbeat();
497}
498}
499while (false);
500
501return result;
502}
503}
504
505
506</script>
507<table id="popupWin" class="popup" cellspacing="0" cellpadding="0" border="0"
508onselectstart="return false;" ondragstart="return false;" style="display:;">
509<tr class="popupCaption" id="popupWin_Caption">
510<td align="center"><img src="images/popup_caption.gif" border="0" alt="" /></td>
511</tr>
512<tr class="popupBody" id="popupWin_Body">
513<td valign="top">
514<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
515<tr>
516<td align="center" valign="top" width="46"
517style="padding-top: 2px;width:46px;" nowrap>
518<img src="images/popup_icon_mail.gif" border="0"
519alt="" id="popupWin_Icon"/>
520</td>
521<td>
522<table cellspacing="0" cellpadding="0" border="0"
523width="100%" height="100%">
524<tr height="18">
525<td valign="bottom"><div id="popupWin_CaptionText"
526class="popupCaptionText">title1</div></td>
527<td align="right" width="18">
528<table cellspacing="1" cellpadding="0"
529border="0" width="18" height="18"
530class="popupButton"
531onmouseover="this.className='popupButtonHover';"
532onmouseout="this.className='popupButton';"
533onmousedown="var img=this.rows[0].cells[0].children[0];img.src=img.src.replace('_black','_white');"
534onmouseup="var img=this.rows[0].cells[0].children[0];img.src=img.src.replace('_white','_black');"
535id="popupWin_MenuButton">
536<tr>
537<td align="center">
538<img src="images/popup_icon_arrow_black.gif"
539border="0" alt="" /></td>
540</tr>
541</table>
542</td>
543<td align="right" width="18">
544<table cellspacing="1" cellpadding="0" border="0" width="18"
545height="18" class="popupButton"
546onmouseover="this.className='popupButtonHover';"
547onmouseout="this.className='popupButton';"
548id="popupWin_CloseButton">
549<tr>
550<td align="center">
551<img src="images/popup_icon_close.gif"
552border="0" alt="" /></td>
553</tr>
554</table>
555</td>
556</tr>
557<tr>
558<td colspan="2" valign="top">
559<div id="popupWin_BodyText" class="popupBodyText">
560![]()
561</div>
562</td>
563</tr>
564<tr height="8">
565<td/>
566<td/>
567</tr>
568</table>
569</td>
570</tr>
571</table>
572</td>
573</tr>
574</table>
575
576<div class="popupMenu" id="popupWin_Menu">
577<table cellspacing="0" cellpadding="0" border="0" width="100%"
578height="100%" class="popupMenuTable">
579<tr height="22">
580<td class="popupMenuRow" onmouseover="this.className='popupMenuRowHover';"
581onmouseout="this.className='popupMenuRow';" id="popupWin_Menu_Disable">
582<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
583<tr>
584<td width="28"> </td>
585<td><span>Disable Popup</span></td>
586</tr>
587</table>
588</td>
589</tr>
590<tr height="3">
591<td>
592<div class="popupMenuSep"><img height="1px"></div>
593</td>
594</tr>
595<tr height="22">
596<td class="popupMenuRow" onmouseover="this.className='popupMenuRowHover';"
597onmouseout="this.className='popupMenuRow';"
598id="popupWin_Menu_Setting" URL="/User/EditProfile.aspx?ReturnUrl=/driver.aspx">
599<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
600<tr>
601<td width="28"> </td>
602<td><span>Popup Setting</span></td>
603</tr>
604</table>
605</td>
606</tr>
607</table>
608</div>
609
610<script>
611var popupManager = new PopupManager();
612window.setInterval("popupManager.Heartbeat();", 1500); // 更新
613var p = popupManager.AddPopup("popupWin", "My PM Content", "", "My PM Subject", func);
614p.PostID = 1;
615p = popupManager.AddPopup("popupWin", "New Post Content1",
616"images/popup_icon_Post.gif", "New Post Subject1", func);
617p.PostID = 2;
618p = popupManager.AddPopup("popupWin", "New Post Content2",
619"images/popup_icon_Post.gif", "New Post Subject2", func);
620p.PostID = 3;
621
622function func(popup)
623{
624alert("PostID:" + popup.PostID)
625}
626</script>
627



.popup
font-size


浙公网安备 33010602011771号