]
javascript popup window centering code
The following are two examples of pop-up windows centered on the screen
The code is as follows:
window.open() method
function ShowDialog( url) {
var iWidth=300; //Window width
var iHeight=200; //Window height
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 method
The code is as follows:
function ShowDialog(url) {
var iWidth= 300; //Window width
var iHeight=200;//Window height
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");
}
Note the second parameter here, window
Users must enter information in this pop-up form before they can access other forms. It is a modal form, so just use the second method
The javascript pop-up window is centered four:
The code is as follows:
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"
);
}
Note: 500 and 750 are hard-coded and can be passed in through parameters.