Get the viewable area in the browser window in JavaScript

Source: Internet
Author: User
Tip: You can modify some of the code before running

<style type= "Text/css" > body {height:100%; margin:0; padding:0; } #warp {Position:absolute; top:0; left:0; Background: #059B9A; z-index:100; Filter:alpha (OPACITY=50); /* IE */-moz-opacity:0.5; /* Moz + FF * * * opacity:0.5; } </style> <script type= "Text/javascript" > Function Getviewportinfo () {var w = (window.innerwidth)? window . Innerwidth: (document.documentelement && document.documentElement.clientWidth)? Document.documentElement.clientWidth:document.body.offsetWidth; var h = (window.innerheight)? Window.innerheight: (document.documentelement && document.documentElement.clientHeight)? Document.documentElement.clientHeight:document.body.offsetHeight; return {w:w,h:h}; }; function Setel () {var info = getviewportinfo (); var el = document.getElementById (' warp '); = info.h + ' px '; = info.w + ' px '; } window.onload = function () {Setel ();} window.onresize = function () {Setel ();} </script> <div id= "warp" onclick= "document.getElementById" (' Warp '). style.display= ' None ' "></div> <div > If you see a semi-transparent layer, and the window does not appear with scrollbars, the example works fine. <br/> Click to close the transparent layer. </div></td> </tr> </table>
Tip: You can modify some of the code before running
Related Article

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: 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.