//浏览器类型及版本检测
function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
} //参数列表:
//txt:显示文本
//time:显示时间
//url:按“确定”后跳转的地址
//script:按“确定”后执行的脚本
//isdrav:是否可拖动
window.alert = function(txt,time,url,script,isdrav)
{
var shield = document.createElement("DIV");
shield.id = "AlertDiv";
shield.style.position = "absolute";
shield.style.left = "0px";
shield.style.top = "0px";
shield.style.width = "100%";
var sheight;
if(getOs()=="MSIE")
{
shield.style.height=window.screen.height+getScrollTop();
}
else
{
shield.style.height="100%";
}
shield.style.background = "#333333";
shield.style.textAlign = "center";
shield.style.zIndex = "100000";
shield.style.filter = "alpha(opacity=70)";
var alertFram = document.createElement("DIV");
alertFram.id="alertFram";
alertFram.style.position = "absolute";
alertFram.style.right = "50%";
alertFram.style.bottom = "50%";
alertFram.style.marginRight = "-125px";
alertFram.style.marginBottom = "-75px";
alertFram.style.width = "250px";
alertFram.style.height = "auto";
//alertFram.style.background = "#fff";
alertFram.style.textAlign = "center";
alertFram.style.lineHeight = "";
alertFram.style.zIndex = "100002";
//strHTML的几个css要自己去改写了,这里就不给了
strHtml = "<ul class='Alertform'>\n";
strHtml += "<li ";
if(isdrav!=null && isdrav =="true")
{
strHtml +=" onmousedown=\"oMove(event);\" title=\"按住鼠标左键可进行拖动\" style='cursor:move;' ";
}
strHtml += " class='Alerttitle'>XXXXX友情提醒:</li>\n";
strHtml += "<li class='AlertMessage'>"+txt+"</li>\n";
strHtml += "<li class='AlertBtn'><input type='submit' value=' 确定 ' onclick=\"remove();\"></li>\n";
strHtml += "</ul>\n";
alertFram.innerHTML = strHtml;
document.body.appendChild(alertFram);
document.body.appendChild(shield);
var c = 70;
this.doAlpha = function(){
if (c++ > 70){clearInterval(ad);return 0;}
shield.style.filter = "alpha(opacity="+c+");";
}
this.remove=function(){ if(url!=null && url!="")
{
//判断在哪里刷新
if(url.split('|').length>1)
{
top.location.href=url.split('|')[1];
}
else
{
location.href = url;
}
}
if(script!=null && script!="")
{
script;
}
alertFram.innerHTML="";
shield.style.filter = "";
shield.style.display="none";
shield.id = "";
shield.style.position = "";
shield.style.left = "";
shield.style.top = "";
shield.style.width = "";
shield.style.height ="";
shield.style.background = "";
shield.style.textAlign = "";
shield.style.zIndex = "0";
shield.style.filter = "";
alertFram.id="";
alertFram.style.position = "";
alertFram.style.left = "";
alertFram.style.top = "";
alertFram.style.marginLeft = "";
alertFram.style.marginTop = "";
alertFram.style.width = "";
alertFram.style.height = "";
alertFram.style.background = "";
alertFram.style.textAlign = "";
alertFram.style.lineHeight = "";
alertFram.style.zIndex = "0";
alertFram.style.display="none";
if(setime!=null)
{
clearInterval(setime);
}
}
var ad = setInterval("doAlpha()",1);
alertFram.focus();
document.body.onselectstart = function(){return false;};
if(time!=""&&time!=0&&time!=null)
{
var setime= setInterval("remove()",time);
}
}var ie=document.all;
var nie=document.getElementById&&!document.all;
var otop,oleft;
var obj;
var isdrag=false;
function oMove(e){ obj = nie?e.target : event.srcElement;
var topElement = "HTML";
while (obj.tagName != topElement && obj.id != "alertFram") {
obj = nie ? obj.parentNode : obj.parentElement;
}
if (obj.id=="alertFram") {
isdrag = true;
otop = nie ? e.clientY- obj.offsetTop:event.y - obj.offsetTop;
oleft = nie ? e.clientX- obj.offsetLeft:event.x - obj.offsetLeft;
//设置捕获范围
if(obj.setCapture){
obj.setCapture();
}else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE);
}
obj.onmousemove = moveMouse;
obj.onmouseup = function()
{
obj.onmousemove = null;
obj.style.filter = null;
//取消捕获范围
if(obj.releaseCapture){
obj.releaseCapture();
}else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE);
}
//清除事件
obj.onmouseup=null;
} return false;
}}
function moveMouse(e)
{
if (isdrag) {
var top = nie ? e.clientY - otop : event.clientY - otop;
var left = nie ? e.clientX - oleft : event.clientX - oleft;
top = top>0?top:0;
left = left>0?left:0;
//top = top>document.body.scrollHeight?document.body.scrollHeight:top;
left = left>document.body.scrollWidth-2-parseInt(obj.style.width)?document.body.scrollWidth-2-parseInt(obj.style.width):left;
obj.style.top = top+"px";
obj.style.left = left+"px";
}
return false;}
document.onmouseup=new Function("isdrag=false");
function getScrollTop() {
var scrollPos = 0;
if (typeof window.pageYOffset != 'undefined') {
scrollPos = window.pageYOffset;
}
else if (typeof window.document.compatMode != 'undefined' &&
window.document.compatMode != 'BackCompat') {
scrollPos = window.document.documentElement.scrollTop;
}
else if (typeof window.document.body != 'undefined') {
scrollPos = window.document.body.scrollTop;
}
return scrollPos;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货