<div id="IsDiv">弹出的DIV</div>
在页面结束后调用
</form>
</body>
<script language="javascript" type="text/javascript">
popDiv("IsDiv", '<%=ViewState["displayFlag"] %>', 10);
</script>
</html>
在后台通过更改 ViewState["displayFlag"] 的属性确定是否弹出(false 隐藏,true弹出)
JS 代码,放入到JS文件中引用即可
function popDiv(showId, flag,index) {
var h = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + 'px';
var w = document.documentElement.scrollWidth + 'px';
var popCss = "background:#000;opacity:0.3;filter:alpha(opacity=20);position:absolute;left:0;top:0;overflow:hidden;"
var exsit = document.getElementById(showId + "_popIframe");
if (!exsit) {
pop_Box = document.createElement("div"); pop_Box.id = showId + "_popBox";
document.getElementsByTagName("body")[0].appendChild(pop_Box);
pop_Box.style.cssText = popCss; pop_Box.style.zIndex = index;
pop_Box.style.height = h; pop_Box.style.width = w;
pop_Iframe = document.createElement("iframe");
pop_Iframe.id = showId + "_popIframe";
document.getElementsByTagName("body")[0].appendChild(pop_Iframe);
pop_Iframe.style.cssText = popCss;
pop_Iframe.style.zIndex = index - 1;
pop_Iframe.style.height = h; pop_Iframe.style.width = ((parseInt(w) - 5) > 0 ? (parseInt(w) - 5) : 1) + "px";
}
else {
pop_Box = document.getElementById(showId + "_popBox");
document.getElementsByTagName("body")[0].appendChild(pop_Box);
pop_Box.style.cssText = popCss; pop_Box.style.zIndex = index;
pop_Box.style.height = h; pop_Box.style.width = w;
pop_Iframe = document.getElementById(showId + "_popIframe");
document.getElementsByTagName("body")[0].appendChild(pop_Iframe);
pop_Iframe.style.cssText = popCss;
pop_Iframe.style.zIndex = index - 1;
pop_Iframe.style.height = h;
pop_Iframe.style.width = ((parseInt(w) - 5) > 0 ? (parseInt(w) - 5) : 1) + "px";
}
//BtShow("popIframe"); BtShow("popBox"); BtShow(showId);
var displayValue = "none";
if (flag == "True" || flag == "true") {
displayValue = "block";
}
document.getElementById(showId + "_popBox").style.display = displayValue;
document.getElementById(showId + "_popIframe").style.display = displayValue;
document.getElementById(showId).style.display = displayValue;
pop_Win = document.getElementById(showId);
pop_Win.style.position = "absolute";
pop_Win.style.zIndex = index + 1;
pop_Win.style.top = document.documentElement.scrollTop + document.body.scrollTop + document.documentElement.clientHeight / 2 - pop_Win.offsetHeight / 2 + 'px';
pop_Win.style.left = (document.documentElement.clientWidth / 2 - pop_Win.offsetWidth / 2) + 'px';
}