JavaScript code:
Copy Code code as follows:
function Get_page_size ()
{
var re = {};
if (document.documentelement && document.documentElement.clientHeight)
{
var doc = document.documentelement;
Re.width = (doc.clientwidth>doc.scrollwidth)? Doc.clientwidth-1:doc.scrollwidth;
Re.height = (doc.clientheight>doc.scrollheight)? Doc.clientHeight:doc.scrollHeight;
}
Else
{
var doc = document.body;
Re.width = (window.innerwidth>doc.scrollwidth)? Window.innerWidth:doc.scrollWidth;
Re.height = (window.innerheight>doc.scrollheight)? Window.innerHeight:doc.scrollHeight;
}
return re;
}
904 viewed 3 comment (s)
Code instance:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Get window Size </title>
<script type= "Text/java script" >
function GetPageSize ()
{
var re = {};
if (document.documentelement && document.documentElement.clientHeight)
{
var doc = document.documentelement;
Re.width = (doc.clientwidth>doc.scrollwidth)? Doc.clientwidth-1:doc.scrollwidth;
Re.height = (doc.clientheight>doc.scrollheight)? Doc.clientHeight:doc.scrollHeight;
}
Else
{
var doc = document.body;
Re.width = (window.innerwidth>doc.scrollwidth)? Window.innerWidth:doc.scrollWidth;
Re.height = (window.innerheight>doc.scrollheight)? Window.innerHeight:doc.scrollHeight;
}
Results output to two text boxes
Document.form1.availheight.value= Re.width;
Document.form1.availwidth.value= Re.height;
return re;
}
</script>
<body>
<form action= "#" method= "Get" Name= "Form1" Id= "Form1" >
The actual height of the browser window:
<input type= "text" name= "availheight" size= "4"/>
<br/>
The actual width of the browser window:
<input type= "text" name= "availwidth" size= "4"/>
<br/>
</form>
<script type= "Text/java script" >
GetPageSize ();
Window.onresize=getpagesize;
</script>
</body>