JQ obtains the height and width of the browser window.

Source: Internet
Author: User

Window object
Window object indicates the Window opened in the browser. The top-level object in the JavaScript level, indicating the browser window.
If a document contains a frame (frame or iframe tag), the browser creates a window object for the HTML document and creates an additional window object for each frame.
Note: It is not applicable to the Public Standard of the window object, but all browsers support this object.

JQuery can be used to obtain the width and height of the window as follows:
Width: $ (window). width ()
Height: $ (window). height ()


Actual results:

 



Different browsers on the same screen may have different widths even if they are all maximized. You can open this page in IE, Chrome, and Firefox to view the preceding values.

Complete 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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> obtain the width of the browser window-ke leyi </title>
<Script type = "text/javascript" src = "http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"> </script>
</Head>
<Body>
<Div id = "windowinfo_keleyi_com"> </div>
<Script type = "text/javascript">
$ ("# Export winfo_ke" + "leyi_com" ).html ("width:" + $ (window ). width () + ", height:" + $ (window ). height ());
</Script>
<Div style = "background-color: Red; width: 100%; height: 150px;"> welcome </div>
<Div style = "background-color: Yellow; width: 100%; height: 150px;"> hi </div>
<Div style = "background-color: Silver; width: 100%; height: 150px;"> ke leyi </div>
<Div style = "background-color: Aqua; width: 100%; height: 150px;"> keleyi.com </div>
<Div style = "background-color: Fuchsia; width: 100%; height: 150px;"> keleyi </div>
<Div style = "background-color: Green; width: 100%; height: 150px;"> keleyi.com </div>
<Div style = "background-color: Blue; width: 100%; height: 150px;"> ke leyi </div>
<Div style = "background-color: Olive; width: 100%; height: 150px;"> ke leyi returns to the top </div>
<Div style = "background-color: Green; width: 100%; height: 150px;"> A </div>
<Div style = "background-color: Purple; width: 100%; height: 150px;"> jquery </div>
<Div style = "background-color: Green; width: 100%; height: 150px; "> <a href =" http://keleyi.com/a/bjac/6f008786225269ac.htm "target =" _ blank "> original </a> </div>
<Div style = "background-color: Lime; width: 100%; height: 150px;"> keleyi.com </div>
<Div style = "background-color: Orange; width: 100%; height: 150px;"> complete code </div>
<Div style = "height: 130px;"> </div>

<Div id = "downmsg_emessage" style = "DISPLAY: block">
<Div id = "downmsgBar">
<Div id = "donwmsg_head"> ke leyi recommendation content </div> <a class = "close" href = "javascript: closeDiv () "> </a> <a class =" msg-hidden-btn-1 "id =" msg_hidden_btn "href =" javascript: showHideDiv () "> & nbsp; </a> </div>
<Div id = "donwmsg_content" style = "DISPLAY: block; HEIGHT: 162px">
<Ul>
<Li class = "ll"> <a href = "http://keleyi.com/a/bjac/768f469b95b61487.htm"> intermittent upward scrolling of a single line of text </a> </li>
<Li> <a href = "http://keleyi.com/a/bjac/a6d651710217f7a0.htm"> jQuery UI modifier title bubble </a> </li>
<Li> <a href = "http://keleyi.com/a/bjac/bf0eb8c02085b10d.htm"> jquery clears input boxes such as textarea </a> </li>
<Li> <a href = "http://keleyi.com/a/bjac/939631bb07adb4dc.htm"> jquery light-off effect </a> </li>
<Li> <a href = "http://keleyi.com/a/bjac/7e8897e5ec0849e9.htm"> can change the size of the DIV layer </a> </li>
</Ul>
<Div class = "lb"> <a href = "http://keleyi.com/menu/jquery/" target = "_ blank"> jQuery </a> <a href = "http://keleyi.com/menu/javascript/" target = "_ blank"> Javascript </a> <a href = "http://keleyi.com/menu/cms/" target = "_ blank"> CMS </a> </div>
</Div>
</Div>
</Body>
</Html>

Original article: http://keleyi.com/a/bjac/nk1dr8xn.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.