发布于 3年前
JS实现弹出居中的模式窗口示例
本文实例讲述了JS实现弹出居中的模式窗口。分享给大家供大家参考,具体如下:
<pre class="brush:js;">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS弹出窗口</title>
</head>
<body>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script>
function OpenDialog(url,w, h) {
var iTop2 = (window.screen.availHeight - 20 - h) / 2;
var iLeft2 = (window.screen.availWidth - 10 - w) / 2;
var params = 'menubar:no;dialogHeight=' + h + 'px;dialogWidth=' + w + 'px;dialogLeft=' + iLeft2 + 'px;dialogTop=' + iTop2 + 'px;resizable=yes;scrollbars=0;resizeable=0;center=yes;location:no;status:no'
var addDiv = $("<div id = 'tempDiv' style='left:0px;top:0px;position:absolute;width:100%;height:100%;background:rgba(0,0,0,0.4)!important;filter:alpha(opacity = 40);background:#000;z-index:1000;'></div>");
$(document.body).append(addDiv); //添加一个蒙板作背景
window.open(url, addDiv, params);
}
OpenDialog("https://www.edoou.com",300,300);
</script>
</body>
</html>