Sometimes we need a pop-up window during the webpage creation process. In general, we want the window to be centered.
<Script language = "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);} script Test
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Code Center in the javascript pop-up window
The following are two examples of the screen center window
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 Mode
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 that the second parameter here is window
You must enter information in the pop-up form before accessing other forms. The mode form is the second method.
Center 4 in the javascript pop-up window:
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.