- 纯js编写
- 跨框架
- 无图片
- 支持调速度
- 任意位置弹出
- 需要ie5.5以上
<
HTML
><
HEAD
>
<
SCRIPT language
=
JavaScript
>
<!--

/**/
/*
** ==================================================================================================
** 类名:CLASS_MSN_MESSAGE
** 功能:提供类似MSN消息框
** 示例:
---------------------------------------------------------------------------------------------------
var MSG = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈");
MSG.show();
---------------------------------------------------------------------------------------------------
** 作者:ttyp
** 邮件:ttyp@21cn.com
** 日期:2005-3-18
** ==================================================================================================
**/

/**/
/*
* 消息构造
*/

function
CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action)
{
this.id = id;
this.title = title;
this.caption= caption;
this.message= message;
this.target = target;
this.action = action;
this.width = width?width:200;
this.height = height?height:120;
this.timeout= 150;
this.speed = 20;
this.step = 1;
this.right = screen.width -1;
this.bottom = screen.height;
this.left = this.right - this.width;
this.top = this.bottom - this.height;
this.timer = 0;
this.pause = false;
this.close = false;
this.autoHide = true;
}

/**/
/*
* 隐藏消息方法
*/

CLASS_MSN_MESSAGE.prototype.hide
=
function
()
{

if(this.onunload())
{

var offset = this.height>this.bottom-this.top?this.height:this.bottom-this.top;
var me = this;

if(this.timer>0)
{
window.clearInterval(me.timer);
}

var fun = function()
{

if(me.pause==false||me.close)
{
var x = me.left;
var y = 0;
var width = me.width;
var height = 0;

if(me.offset>0)
{
height = me.offset;
}
y = me.bottom - height;

if(y>=me.bottom)
{
window.clearInterval(me.timer);
me.Pop.hide();

} else
{
me.offset = me.offset - me.step;
}
me.Pop.show(x,y,width,height);
}
}
this.timer = window.setInterval(fun,this.speed)
}
}

/**/
/*
* 消息卸载事件,可以重写
*/

CLASS_MSN_MESSAGE.prototype.onunload
=
function
()
{
return true;
}

/**/
/*
* 消息命令事件,要实现自己的连接,请重写它
*
*/

CLASS_MSN_MESSAGE.prototype.oncommand
=
function
()
{
this.close = true;
this.hide();
}

/**/
/*
* 消息显示方法
*/

CLASS_MSN_MESSAGE.prototype.show
=
function
()
{

var oPopup = window.createPopup(); //IE5.5+
this.Pop = oPopup;
var w = this.width;
var h = this.height;
var str = "<DIV style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: " + w + "px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: " + h + "px; BACKGROUND-COLOR: #c9d3f3'>"
str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>"
str += "<TR>"
str += "<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30 height=24></TD>"
str += "<TD style='PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px' vAlign=center width='100%'>" + this.caption + "</TD>"
str += "<TD style='PADDING-RIGHT: 2px; PADDING-TOP: 2px' vAlign=center align=right width=19>"
str += "<SPAN title=关闭 style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>"
str += "</TR>"
str += "<TR>"
str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=3 height=" + (h-28) + ">"
str += "<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 8px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 8px; BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%'>" + this.title + "<BR><BR>"
str += "<DIV style='WORD-BREAK: break-all' align=left><A href='javascript:void(0)' hidefocus=true id='btCommand'><FONT color=#ff0000>" + this.message + "</FONT></A></DIV>"
str += "</DIV>"
str += "</TD>"
str += "</TR>"
str += "</TABLE>"
str += "</DIV>"
oPopup.document.body.innerHTML = str;
this.offset = 0;
var me = this;


oPopup.document.body.onmouseover = function()
{me.pause=true;}

oPopup.document.body.onmouseout = function()
{me.pause=false;}


var fun = function()
{
var x = me.left;
var y = 0;
var width = me.width;
var height = me.height;

if(me.offset>me.height)
{
height = me.height;

} else
{
height = me.offset;
}
y = me.bottom - me.offset;

if(y<=me.top)
{
me.timeout--;

if(me.timeout==0)
{
window.clearInterval(me.timer);

if(me.autoHide)
{
me.hide();
}
}

} else
{
me.offset = me.offset + me.step;
}
me.Pop.show(x,y,width,height);
}
this.timer = window.setInterval(fun,this.speed)
var btClose = oPopup.document.getElementById("btSysClose");

btClose.onclick = function()
{
me.close = true;
me.hide();
}
var btCommand = oPopup.document.getElementById("btCommand");

btCommand.onclick = function()
{
me.oncommand();
}
}

/**/
/*
** 设置速度方法
**/

CLASS_MSN_MESSAGE.prototype.speed
=
function
(s)
{
var t = 20;

try
{
t = praseInt(s);

} catch(e)
{}
this.speed = t;
}

/**/
/*
** 设置步长方法
**/

CLASS_MSN_MESSAGE.prototype.step
=
function
(s)
{
var t = 1;

try
{
t = praseInt(s);

} catch(e)
{}
this.step = t;
}

CLASS_MSN_MESSAGE.prototype.rect
=
function
(left,right,top,bottom)
{

try
{
this.left = left !=null?left:this.right-this.width;
this.right = right !=null?right:this.left +this.width;
this.bottom = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;
this.top = top !=null?top:this.bottom - this.height;

} catch(e)
{}
}
var
MSG1
=
new
CLASS_MSN_MESSAGE(
"
aa
"
,
200
,
120
,
"
短消息提示:
"
,
"
您有1封消息
"
,
"
今天请我吃饭哈
"
);
MSG1.rect(
null
,
null
,
null
,screen.height
-
50
);
MSG1.speed
=
10
;
MSG1.step
=
5
;
//
alert(MSG1.top);
MSG1.show();
//
同时两个有闪烁,只能用层代替了,不过层不跨框架
//
var MSG2 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有2封消息","好的啊");
//
MSG2.rect(100,null,null,screen.height);
//
MSG2.show();
//
-->
</
SCRIPT
>
<
META content
=
"
MSHTML 6.00.2800.1106
"
name
=
GENERATOR
></
HEAD
>
<
BODY
></
BODY
></
HTML
>
#
re: MSN消息提示类(II)
2005-04-03 00:57
#
re: MSN消息提示类(II)
2005-04-07 17:16
#
re: MSN消息提示类(II)
2005-05-08 17:38
#
re: MSN消息提示类(II)
2005-05-25 14:35
老兄,提醒中的消息,我想使用:
ShowMessage("aa",200,120,"短消息提示:","您有2封消息","<a href='ok.aspx' target='_blank'>好的啊</a>",10,5);
这样的方法给消息添加超连接方式,让我弹出一个窗口来处理。
但调用你的方法,点击没有任何反应。能不能帮忙看看。
回复
#
re: MSN消息提示类(II)
2005-05-25 15:03
to 听棠.NET :
只要修改这个就可以了:
CLASS_MSN_MESSAGE.prototype.oncommand = function()
{
window.open("
http://www.google.com");
this.hide();
}
不能在消息那里写连接
回复
#
re: MSN消息提示类(II)
2005-05-26 10:20
可我是活的,不是写死的,我是希望能传进去调用。而不是写死在方法里,而且,应该是在显示的那条信息语句上点击才弹出。
就跟MSN那样的》》。
回复
#
re: MSN消息提示类(II)
2005-05-26 10:33
老兄,我想了想,就算可以传进去也不好,我有可能不仅仅是window.open(),有可能是showModelDialog()之类,反正,我可能会有自己的好多可能性,因此,最好的方法就是,象我上面那样,可以把字符带进去,自己想怎么样就怎么样。
ShowMessage("aa",200,120,"短消息提示:","您有2封消息","<a href='ok.aspx' target='_blank'>好的啊</a>",10,5);
这个好实现吗?我记得那个服务器的Popup控件也是这样实现的。
回复
#
re: MSN消息提示类(II)
2005-05-26 11:42
你可以随时重写CLASS_MSN_MESSAGE.prototype.oncommand这个方法啊,只要再写一个你自己的CLASS_MSN_MESSAGE.prototype.oncommand方法就可以了(不一定是window.open),因为这个是JS的popup,那个估计是用div做的吧,所以用你那种传参数的形式,内容都是在popup里的,A不能直接在popup里这么用,必须转到调用popup的父页,所以还是要调用oncommand方法,总之,你只要改写oncommand就可以了
回复
#
re: MSN消息提示类(II)
2005-05-26 11:45
如:
CLASS_MSN_MESSAGE.prototype.oncommand = function()
{
window.open(this.action,this.target);
this.hide();
}
var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈","_blank","
http://www.google.com");
MSG1.rect(null,null,null,screen.height-50);
MSG1.speed = 10;
MSG1.step = 5;
MSG1.show();
回复
#
re: MSN消息提示类(II)
2005-06-07 23:42
#
re: MSN消息提示类(II)
2005-06-08 16:40
#
re: MSN消息提示类(II)
2005-06-25 12:04
#
re: MSN消息提示类(II)
2005-07-15 19:03
大哥 您好 我想做一个弹出的东东 我有一个聊天程序 我想把这个应用到类似于msn那样的来了消息会通知你的那种功能 大哥 大概怎么实现啊 我可以付费给你 但是不会多 因为我是学生 谢谢 我的qq 235021847 如果大哥愿意的话 请联系我 谢谢!!!
回复
#
re: MSN消息提示类(II)
2005-07-15 21:12
或者说 可不可以通过别的时间触发这个javascript啊
?比如定义一个函数 当这个函数的某个属性等于一个值就执行这个javascript
回复
#
re: MSN消息提示类(II)
2005-07-15 21:24
两种办法:
1.可以服务端设置cookie,在客户端读,然后显示
2.利用xmlhttp从服务端读取数据,然后显示
回复
#
re: MSN消息提示类(II)
2005-07-25 10:35
发现个问题啊
这样的消息框里的连接会被弹出窗口过滤掉
能解决这个问题么?
回复
#
re: MSN消息提示类(II)
2005-07-28 15:08
你好,我是听棠,用的是你的这个弹出提示窗口,蛮不错的,就是想能否加个功能,就是当鼠标放在弹出的窗口时,窗口能保持在上面,不要自动隐藏。要不然,有时候选不中。
MSN都是这样做的。我的JS实在是太烂,自己加不上去啊。
回复
#
re: MSN消息提示类(II)
2005-07-28 20:34
#
re: MSN消息提示类(II)
2005-08-04 13:12
#
re: MSN消息提示类(II)
2005-08-15 18:37
使用这个弹窗后,正常页面的鼠标不能使用滚轮了啊,是不是焦点的问题。求教于高手!
回复
#
re: MSN消息提示类(II)
2005-09-14 16:44
老兄。又冒出一个问题啊。鼠标放上去,确实可以保持不隐藏了。
但我点击“X”符号,想立即关闭弹出窗口,却关不了???
多谢!兄弟,要是修改好的话,发个mail给通知我一下:tintown_liu@hotmail.com
回复
#
re: MSN消息提示类(II)
2005-09-14 17:15
to 听棠:
呵呵,真是老革命碰上新问题,已经改了,查收邮件
回复
#
re: MSN消息提示类(II)
2005-09-16 13:37
#
re: MSN消息提示类(II)
2005-11-01 09:29
楼主,我想请都教一下如果我使用xmlhttp来从数据库里面最消息,该怎么做呀,还有那个提示如果没有查看的话我不想让他隐藏该如何实现
回复
#
re: MSN消息提示类(II)
2005-11-01 10:37
1.如果是.net可以考虑用ajax,如果不是,专门做一个页面应答xmlhttp请求,返回XML格式文件,然后用js解读,最后显示
2.把
if(me.timeout==0){
window.clearInterval(me.timer);
me.hide();
}
改
if(me.timeout==0){
window.clearInterval(me.timer);
}
或见已修改
回复
#
re: MSN消息提示类(II)
2005-11-02 09:01
#
re: MSN消息提示类(II)
2005-12-07 09:17
这个消息提示类实在太酷了~~
谢谢楼主的分享~~
回复
#
re: MSN消息提示类(II)
2006-01-09 22:31
楼主,这个消息框我一直在用,感觉是不错。但现在又遇到一个新需求哦。哈哈
就是我可能同时会弹出一个以上的消息框,由于一些原因,我不能放在一个框里,想要是遇到一个以上时,能象MSN一样,一个叠在另一个之上,也就是上面的那个应该在底下高度为120的地方往上出现,消失时也是在离底下120的地方消失。哈哈:)
要求是不是蛮高的,我是觉得那样才是完美的,不知道楼主能不能实现:)
回复
#
re: MSN消息提示类(II)
2006-01-10 13:11
抱歉,这个做不到,因为采用的是popup方式,他们会争抢焦点,不过popup好处是不受框架限制。有时间我会做一个采用div方式的,FF兼容多窗口的代码
回复
#
re: MSN消息提示类(II)
2006-02-27 10:32
楼主,我想问你一个问题,就是假如说我提示的消息有二个我该怎么处理呀,比如说,第一行内容是我要吃饭,第二行的内容是下班了,当然,二个内容的链接也不一样,请问楼主能实现吗,
回复
#
re: MSN消息提示类(II)
2006-02-27 13:56
你可以处理你的消息内容啊啊,如:
<a href='
http://url1'>我要吃饭</a><br><a href='
http://url2'>我要下班</a>
回复
#
re: MSN消息提示类(II)
2006-02-27 17:58
为什么有时候弹不出来呀,我的是IE6,有时候可以弹出来,
回复
#
re: MSN消息提示类(II)
2006-02-28 09:05
楼主说的很对啊,此弹出窗口的最大优点就是popup弹出,可以随时弹出来,而这同时也遇到一个问题,如果我的网页上使用了模式对话框就麻烦了。无法抢得焦点,而在关闭模式对话框时,会弹出N多的消息来。
关于有两个消息弹出时,既然不能象MSN一样层叠出现,那么可以使用延迟弹出,程序在发现有两个以上消息要弹出时,可以输出客户端脚本来延迟执行,setTimeout("Message(..)","5000");象这样五秒后弹出来:)
我就是实现了这种方式,还算不错:)暂时这样解决是最好的了。
回复
#
re: MSN消息提示类(II)
2006-02-28 09:14
各位有遇到过有时不能弹出的现象吗,我碰到的情况是第一次打开那网页不行,第二次就可以正常弹出,请问楼主这是什么原因呀,该不会与缓存有关吧!
回复
#
re: MSN消息提示类(II)
2006-02-28 09:29
@听棠.NET
像多个弹出的,我是在弹出提示前,做了个标记,在这个标记为真前,不读取下一个提示内容,在弹出提示消失后在设置此标记为假,然后读取下一条记录,当然延迟也不错,不过延迟的时间要大于提示的显示时间
@阳光男孩
一般是你程序的问题,可能第一次没执行到那
回复
#
re: MSN消息提示类(II)
2005-03-18 15:26
评论