Javascript: code _ javascript skills centered in the pop-up window

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.