javascript之弹出窗口居中的代码
function openWin(u, w, h) {
var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
var s = 'width=' + w + ', height=' + h + ', top=' + t + ', left=' + l;
s += ', toolbar=no, scrollbars=no, menubar=no, location=no, resizable=no';
open(u, 'oWin', s);
}
Test
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
javascript弹出窗口居中代码
下面给两个弹出屏幕居中窗口的例子
window.open()方式
function ShowDialog(url) {
var iWidth=300; //窗口宽度
var iHeight=200;//窗口高度
var iTop=(window.screen.height-iHeight)/2;
var iLeft=(window.screen.width-iWidth)/2;
window.open(url,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,
Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
}
window.showModalDialog方式
function ShowDialog(url) {
var iWidth=300; //窗口宽度
var iHeight=200;//窗口高度
var iTop=(window.screen.height-iHeight)/2;
var iLeft=(window.screen.width-iWidth)/2;
window.showModalDialog(url,window,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;
dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no");
}
注意这里的第二个参数,window
用户必须在这个弹出式窗体中输入信息后才能访问其他的窗体是模态窗体就是用第二个方法就好了
javascript弹出窗口居中四:
function selectCustomer(){
var iTop = (window.screen.availHeight-30-500)/2;
var iLeft = (window.screen.availWidth-10-750)/2;
window.open("../customer/creditApprManage.do?method=toGetCustomer",
"searchCorp",
"height=500,width=750,top="+iTop+",left="+iLeft+",toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no"
);
}
说明:500和750是硬编码,可以通过参数传入。