前两天做了类似msn消息提示的web桌面提醒,可以跨框架区域,并且支持多窗口并存,下面给出实现方法:
1.利用Popup可以跨框架不受限制的特点,构造一个底层的容器
/**//*
* 底层Popup构造
*/
function Popup(id,width,height){
this.id = id;
this.width = width?width:200;
this.height = height?height:120;
this.Divs=""; //存放DIV层代码,以便写入Popup容器中
this.degree=0; // DIV层数
}
2.在容器内构造重叠的DIV,实现多窗口并存功能
Popup.prototype.BuildDivs= function(degree,message,VISIBILITY,url)
{
this.degree=degree;
var str = "<div id=div_"+ degree +" style='VISIBILITY: "+ VISIBILITY +"; POSITION: absolute; TOP: 0px; LEFT: 0px; Z-INDEX:9;'>";
……(省略)
this.Divs+=str;
}
3./**//*
* 消息显示方法
*/
Popup.prototype.show = function(){
var oPopup = window.createPopup(); //IE5.5+
oPopup.document.body.innerHTML = this.Divs;
……(略去)
}
4.调用方法
var POP = new CLASS_MSN_MESSAGE("P_popup",264.5,164.5);
POP .BuildDivs(1,"您有1封消息","visible","http://www.google.com");
POP .BuildDivs(2,"您有2封消息","visible","http://www.google.com");
POP .BuildDivs(3,"您有3封消息","visible","http://www.google.com");
POP.show();