After the Web modal dialog box is loaded, it dynamically changes its size based on the loaded content and centers it.

Source: Internet
Author: User

A few days ago, I checked dbnetgrid and found that the pop-up window can automatically change its size according to the window content.CodeThe code below plays a role.
<Script language = "JavaScript">
<! --

Window. setTimeout (sizedialog, 1 );

Function sizedialog ()
{
Dialogheight = (parseint (layout. offsetheight) + 30) + "PX ";
Dialogwidth = (parseint (layout. offsetwidth) + 10) + "PX ";
}

// -->
</SCRIPT>
Note: layout in the above Code is the ID of a table in the body. All controls on the page are contained in this table and their width and height attributes are not set.

So I used it in my own Program Application in, because I recently made a task to automatically generate queries, input, and modify interfaces based on the data dictionary, it is very useful. After opening the window to dynamically generate the interface, you can set the size of a window in an adaptive manner, so you do not have to worry about opening a window as much as possible.
However, it is still found that the modal window cannot be centered after its size is changed automatically, and dbnetgrid cannot be centered automatically, I thought it was impossible to automatically center. But today, I was inspired by the sudden increase, so I modified the Code as follows:
<Script language = "JavaScript">
<! --

Window. setTimeout (sizedialog, 1 );

Function sizedialog ()
{
Dialogheight = (parseint (layout. offsetheight) + 30) + "PX ";
Dialogwidth = (parseint (layout. offsetwidth) + 10) + "PX ";
Window. setTimeout (centerdialog, 1 );
}

Function centerdialog ()
{
VaR topposition = (screen. Height )? (Screen. Height-parseint (dialogheight)/2: 0;
VaR leftposition = (screen. width )? (Screen. Width-parseint (dialogwidth)/2: 0;
Dialogtop = topposition;
Dialogleft = leftposition;
}

// -->
</SCRIPT>

When running, everything is OK. The window opened can not only change its size according to its own content, but also be centered after the change. (My memory is not good, so I want to record it here and also provide a method for my friends)
Demo: http://www.openlab.com.cn /~ COMY/mp.htm

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.