Code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Title > Adjust the browser window </ Title >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = gb2312" >
</ Head >
< Body >
< H2 Align = "Center" >
Adjust the browser window size </ H2 >
< HR >
< Form Action = "#" Method = "Get" Name = "Form1" ID = "Form1" >
<! -- Display the actual size of the browser window -->
The actual height of the browser window:
< Input Type = "Text" Name = "Availheight" Size = "4" > < BR >
Actual browser window width:
< Input Type = "Text" Name = "Availwidth" Size = "4" > < BR >
</ Form >
< Script Type = "Text/JavaScript" >
<! --
VaR Winwidth = 0 ;
VaR Winheight = 0 ;
Function Finddimensions () // Function: Obtain the dimension.
{
// Get window width
If (Window. innerwidth)
Winwidth = Window. innerwidth;
Else If (Document. Body) && (Document. Body. clientwidth ))
Winwidth = Document. Body. clientwidth;
// Retrieve window height
If (Window. innerheight)
Winheight = Window. innerheight;
Else If (Document. Body) && (Document. Body. clientheight ))
Winheight = Document. Body. clientheight;
// Detects the body in the document to obtain the window size.
If (Document.doc umentelement && Document.doc umentelement. clientheight &&
Document.doc umentelement. clientwidth)
{
Winheight = Document.doc umentelement. clientheight;
Winwidth = Document.doc umentelement. clientwidth;
}
// The result is output to two text boxes.
Document. form1.availheight. Value = Winheight;
Document. form1.availwidth. Value = Winwidth;
}
Finddimensions (); // Call a function to obtain a value
Window. onresize = Finddimensions;
// -->
</ Script >
</Body>
</Html>