Example 005 control pop-up window Center Display Instance DescriptionClick the button on the page to pop up the window and center the window. Technical EssentialsThis example first applies the open () method of the Window object in JavaScript, opens a new window of the specified size, and then passes through the screen object, obtains the display resolution, and then passes the MoveTo () method of the Window object based on the obtained value. Moves the new window to the center of the screen. The MoveTo () method moves the window to the specified coordinates (x, y) in the following syntax format.
Window.moveto (x, y)
where parameter x, y represents the coordinate value at the position where the window is moved. the Screen object is an onscreen object in JavaScript that reflects the current user's screen settings.
Common properties of the screen object
Properties |
Description |
Width |
The horizontal size of the user's entire screen, in pixels |
Height |
The vertical size of the user's entire screen, in pixels |
Pixeldepth |
Number of bits per pixel of the display |
ColorDepth |
Returns the number of digits used for the current color setting, 1 for black and white, 8 for 256 colors, 16 for enhanced color, and 24/32 for True Color Color. The 8-bit color supports 256 colors, and 16-bit colors (often called "enhanced colors") support about 64000 colors, while 24-bit colors (often called "true Colors") support about 16 million colors. |
Availheight |
Returns the vertical size of the window's content area, in pixels |
Availwidth |
Returns the horizontal dimension of the window's content area, in pixels |
Implementation process1. The window to pop upnew.html
2. The page that implements the functionindex.html<span Style= "FONT-SIZE:14PX;" >
Note: The content of the style tag is the knowledge of CSS, and we focus on the content within the script tag. So this example of ours is done.
JavaScript effect Instance 005-control pop-up window center display