JS实现定时页面弹出类似QQ新闻的提示框

时间:2021-05-26

还是在做联通IOM项目时遇到的一个需求,要求页面每隔半小时弹出一次提示消息(消息以类似QQ新闻的形式弹出)。当时上网找的这么一个资料,已经不记得原文出处了
复制代码 代码如下:
<html>
<head>
<title>JavaScript提示框</title>

<script type="text/javascript">
<!--

/**
* 类名:CLASS_MSN_MESSAGE
* 功能:提供类似MSN消息框
* 示例:
* var MSG = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈");
* MSG.show();
* 消息构造
*/
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);
} 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();
window.open("http://mand();
}
var ommand = oPopup.document.getElementById("ommand");
ommand.onclick = function(){
this.close = true;
me.hide();
window.open(ommand.href);
}
}
/*
* 设置速度方法
*/
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",240,150,"管理员:","思路决定出路","迷失路上");
MSG1.rect(null,null,null,screen.height-50);
MSG1.speed = 10;
MSG1.step = 5;
//alert(MSG1.top);
//MSG1.show();
//同时两个有闪烁,只能用层代替了,不过层不跨框架


/**
* 显示提示框
*/
function showMSG(){
MSG1.show();
}

</script>
</head>

<body>
<center>
<bgsound src="" id="bs" loop="no">
<input type="button" value="按钮" onclick="showMSG(); ">
<br>
<hr>
</center>
</body>
</html>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章