我重载了js的alert函数,但是有个问题,如果网页包涵 <%@include file="testjsp" %>,而在test.jsp里有个重载过的alert的话,那么这个alert就会处在test.jsp的中间,而不是浏览器窗口的中间。而且我的覆盖层也只能覆盖整个test.jsp,不能覆盖到父框架,看看大家有没有什么解决的办法。代码如下:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 2</title>
<script language="javascript">
<!--
function cry(){
alert("你可以把这些select遮住吗????????")
}
//-->
</script>
<script language="javascript">
<!--
window.alert = function(txt)
{
var shield = document.createElement("DIV");
shield.id = "shield";
shield.style.position = "absolute";
shield.style.left = "0px";
shield.style.top = "0px";
shield.style.width = "100%";
shield.style.height = document.body.scrollHeight+"px";
shield.style.background = "blue";
shield.style.textAlign = "center";
shield.style.zIndex = "10000";
shield.style.filter = "alpha(opacity=0)";
var iframe = document.createElement("iframe");
iframe.id = "iframe";
iframe.style.scrolling="0";
iframe.style.frameborder="0";
iframe.style.position = "absolute";
iframe.style.left = "0px";
iframe.style.top = "0px";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.filter = "alpha(opacity=0)";
iframe.style.zIndex = "9999";
var alertFram = document.createElement("DIV");
alertFram.id="alertFram";
alertFram.style.position = "absolute";
alertFram.style.left = "50%";
alertFram.style.top = "50%";
alertFram.style.marginLeft = "-125px";
alertFram.style.marginTop = "-75px";
alertFram.style.width = "250px";
alertFram.style.height = "75px";
alertFram.style.background = "#000";
alertFram.style.textAlign = "center";
alertFram.style.lineHeight = "75px";
alertFram.style.zIndex = "10001";
strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
strHtml += "<li style=\"background:#002F9C;text-align:left;padding-left:5px;font-size:14px;font-weight:bold;color: #FFFFFF;height:25px;line-height:25px;border-left:1px solid #FFFFFF;border-top:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\"></li>\n";
strHtml += "<li style=\"background:#5A7EDC;text-align:center;font-size:12px;color: #FFFFFF;height:75px;line-height:75px;border-left:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\">"+txt+"</li>\n";
strHtml += "<li style=\"background:#002F9C;text-align:center;font-weight:bold;height:25px;line-height:25px; border-left:1px solid #FFFFFF;border-bottom:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\"><input type=button value=' OK ' onclick=\"remove()\"></li>\n";
strHtml += "</ul>\n";
alertFram.innerHTML = strHtml;
document.body.appendChild(alertFram);
document.body.appendChild(iframe);
document.body.appendChild(shield);
var c = 0;
this.doAlpha = function(){
if (c++ > 50){clearInterval(ad);return 0;}
shield.style.filter = "alpha(opacity="+c+");";
}
this.remove=function(){
alertFram.innerHTML="";
shield.style.filter = "";
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 = "";
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 = "";
document.body.removeChild(iframe);
}
var ad = setInterval("doAlpha()",10);
alertFram.focus();
document.body.onselectstart = function(){return false;};
}
//-->
</script>
</head>
<body>
<input type=submit name="cry" value="点击我一下下^_^" style="width: 110px; height: 30px" onclick='return cry();'></input><br><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select>11111111111111111<br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select>1111111111111111111<br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select>
<p>
</p>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 2</title>
<script language="javascript">
<!--
function cry(){
alert("你可以把这些select遮住吗????????")
}
//-->
</script>
<script language="javascript">
<!--
window.alert = function(txt)
{
var shield = document.createElement("DIV");
shield.id = "shield";
shield.style.position = "absolute";
shield.style.left = "0px";
shield.style.top = "0px";
shield.style.width = "100%";
shield.style.height = document.body.scrollHeight+"px";
shield.style.background = "blue";
shield.style.textAlign = "center";
shield.style.zIndex = "10000";
shield.style.filter = "alpha(opacity=0)";
var iframe = document.createElement("iframe");
iframe.id = "iframe";
iframe.style.scrolling="0";
iframe.style.frameborder="0";
iframe.style.position = "absolute";
iframe.style.left = "0px";
iframe.style.top = "0px";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.filter = "alpha(opacity=0)";
iframe.style.zIndex = "9999";
var alertFram = document.createElement("DIV");
alertFram.id="alertFram";
alertFram.style.position = "absolute";
alertFram.style.left = "50%";
alertFram.style.top = "50%";
alertFram.style.marginLeft = "-125px";
alertFram.style.marginTop = "-75px";
alertFram.style.width = "250px";
alertFram.style.height = "75px";
alertFram.style.background = "#000";
alertFram.style.textAlign = "center";
alertFram.style.lineHeight = "75px";
alertFram.style.zIndex = "10001";
strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
strHtml += "<li style=\"background:#002F9C;text-align:left;padding-left:5px;font-size:14px;font-weight:bold;color: #FFFFFF;height:25px;line-height:25px;border-left:1px solid #FFFFFF;border-top:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\"></li>\n";
strHtml += "<li style=\"background:#5A7EDC;text-align:center;font-size:12px;color: #FFFFFF;height:75px;line-height:75px;border-left:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\">"+txt+"</li>\n";
strHtml += "<li style=\"background:#002F9C;text-align:center;font-weight:bold;height:25px;line-height:25px; border-left:1px solid #FFFFFF;border-bottom:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\"><input type=button value=' OK ' onclick=\"remove()\"></li>\n";
strHtml += "</ul>\n";
alertFram.innerHTML = strHtml;
document.body.appendChild(alertFram);
document.body.appendChild(iframe);
document.body.appendChild(shield);
var c = 0;
this.doAlpha = function(){
if (c++ > 50){clearInterval(ad);return 0;}
shield.style.filter = "alpha(opacity="+c+");";
}
this.remove=function(){
alertFram.innerHTML="";
shield.style.filter = "";
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 = "";
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 = "";
document.body.removeChild(iframe);
}
var ad = setInterval("doAlpha()",10);
alertFram.focus();
document.body.onselectstart = function(){return false;};
}
//-->
</script>
</head>
<body>
<input type=submit name="cry" value="点击我一下下^_^" style="width: 110px; height: 30px" onclick='return cry();'></input><br><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select>11111111111111111<br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select>1111111111111111111<br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select><br><br>
<select size="1" name="ds_lb" style=width:100%><option selected value="">请选择</option><option value="1">选项1</option><option value="2">选项2</option></select>
<p>
</p>
</body>
</html>
还是frame框架前者只是服务端代码,客户端是一致的,没这种问题
后者可以重载父框架的alert,然后在test.jsp的alert中调用parent.alert
还有我的另一个问题是怎么样让弹出的alert总是在窗口的中间,也就是不管页面怎么拉,最后提示窗口都要出现在窗口的中间和页面就没有什么关系了。