Tip: JS: Get the browser window size. Get the screen, browser, and webpage height and width.

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

 

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.