JS obtains the width and height of the screen and the usage of window. Open

Source: Internet
Author: User
Tags blank page

From: http://hi.baidu.com/zhuifengh2o/item/4cba119a95b69837336eebe0

 

123 <script>         alert(screen.width + "*" + screen.height)        </script>

Outputs the width and height of the current screen;

12345678910111213 <SCRIPT  LANGUAGE="JavaScript">         var s = "Visible area width :" + document.body.clientWidth;         s += "\ R \ n webpage visible area Height :" + document.body.clientHeight;         s += "\ R \ n web page text width :" + document.body.scrollWidth;         s += "\ R \ n webpage text Height :" + document.body.scrollHeight;         s += "\ R \ n :" + window.screenTop;         s += "\ R \ n left part of the webpage body :" + window.screenLeft;         s += "\ R \ n screen resolution Height :" + window.screen.height;         s += "\ R \ n screen resolution width :" + window.screen.width;         s += "\ R \ n available workspace Height :" + window.screen.availHeight;         s += "\ R \ n available workspace width :" + window.screen.availWidth;         alert(s);        </SCRIPT>

Document. Body. clientwidth ==> body object width
Document. Body. clientheight ==> body object height

Document.doc umentelement. clientwidth ==> visible area width
Document.doc umentelement. clientheight => visible area height

The width and height of each part of the output webpage;

123 <script>             window.open('Default.aspx''newwindow''height=500, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')     </script>

Window. Open usage:

Default. aspx: page to be opened
Newwindow: Window name, which can also be _ Self, _ blank, and other parameters
Height: window height
Width: The window width.
Toolbar: whether to display the toolbar (yes, no)
Menubar: whether to display the menu bar (yes, no)
Scrollbars: whether a scroll bar (yes, no) appears)
Resizable: whether the window size can be changed (yes, no)
Location: whether to display the address bar (yes, no)
Status: whether to display the status bar (yes, no)
Top, left: coordinates when the window is opened;

12345678 <script>            function centerWindow(url, w, h) {                l = (screen.width - w) / 2                t = (screen.height - h) / 2                window.open(url, ''"height=" + w + ",width=" + h + ",top=" + t + ",left=" + l + "");            }       </script>       <input  type="button"onclick="centerWindow('http://www.youth21.i.sohu.com','400','400')"/>

Open a new page center display; open a blank page centerwindow ('about: blank ', 800,500)

1234567891011121314 <SCRIPT  LANGUAGE="JavaScript">         redirectPage();         function redirectPage() {             /* Var url640x480 = "http://www.baidu.com"; ** remember to change the corresponding page */        var url800x600 = "http://www.baidu.com";             var url1024x768 = "http://youth21.i.sohu.com";             /*if  ((screen.width  ==  640)  &&  (screen.height  ==  480))                window.location.href=  url640x480;*/        if (screen.width <= 800)                 window.location.href = url800x600;             else if ((screen.width >= 1024))                 window.location.href = url1024x768;         }      </script>

Open different pages based on the resolution or screen width;

 

1234567891011121314151617 Space Home http://hi.baidu.com/zhuifengh2o     Man man http://hi.baidu.com/zhuifengh2o/archive/tag/hourman     Computer profile http://hi.baidu.com/zhuifengh2o/archive/tag/pc     Article http://hi.baidu.com/zhuifengh2o/archive/tag/article     Meitu http://hi.baidu.com/zhuifengh2o/archive/tag/image     Video http://hi.baidu.com/zhuifengh2o/archive/tag/movie     Game http://hi.baidu.com/zhuifengh2o/archive/tag/game     Web Knowledge http://hi.baidu.com/zhuifengh2o/archive/tag/web     Network Engineering http://hi.baidu.com/zhuifengh2o/archive/tag/network%20engineer

 

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.