我想取得浏览器中,中间显示网页内容的区域大小(不包括滚动条),因为我想通过js建立一个div,使她能够正好覆盖浏览器的内容区域。
我在网上搜索到了这个:
function displayScreenSize()
{
var bodyWidth =document.body.clientWidth; //网页可见区域宽
var bodyHeight =document.body.clientHeight; //网页可见区域高
var bodyWidthWithBorder =document.body.offsetWidth; //网页可见区域宽(包括边线的宽)
var bodyHeightWithBorder=document.body.offsetHeight; //网页可见区域高(包括边线的宽)
var bodyWidthWithScroll =document.body.scrollWidth; //网页正文全文宽
var bodyHeightWithScroll=document.body.scrollHeight; //网页正文全文高
var bodyTopHeight =document.body.scrollTop; //网页被卷去的上边距
var bodyLeftWidth =document.body.scrollLeft; //网页被卷去的左边距
var windowTopHeight =window.screenTop; //网页正文部分上边距
var windowLeftWidth =window.screenLeft; //网页正文部分左边距
var screenHeight =window.screen.height; //屏幕分辨率的高
var screenWidth =window.screen.width; //屏幕分辨率的宽
var screenAvailHeight =window.screen.availHeight; //屏幕可用工作区高度
var screenAvailWidth =window.screen.availWidth; //屏幕可用工作区宽度
var Str="<p>";
Str+="网页可见区域宽:<span class='data'>"+bodyWidth+"px</span><br>";
Str+="网页可见区域高:<span class='data'>"+bodyHeight+"px</span><br>";
Str+="网页可见区域宽(包括边线的宽):<span class='data'>"+bodyWidthWithBorder+"px</span><br>";
Str+="网页可见区域高(包括边线的宽):<span class='data'>"+bodyHeightWithBorder+"px</span><br>";
Str+="网页正文全文宽:<span class='data'>"+bodyWidthWithScroll+"px</span><br>";
Str+="网页正文全文高:<span class='data'>"+bodyHeightWithScroll+"px</span><br>";
Str+="网页被卷去的上边距:<span class='data'>"+bodyTopHeight+"px</span><br>";
Str+="网页被卷去的左边距:<span class='data'>"+bodyLeftWidth+"px</span><br>";
Str+="网页正文部分上边距:<span class='data'>"+windowTopHeight+"px</span><br>";
Str+="网页正文部分左边距:<span class='data'>"+windowLeftWidth+"px</span><br>";
Str+="屏幕分辨率的高:<span class='data'>"+screenHeight+"px</span><br>";
Str+="屏幕分辨率的宽:<span class='data'>"+screenWidth+"px</span><br>";
Str+="屏幕可用工作区高度:<span class='data'>"+screenAvailHeight+"px</span><br>";
Str+="屏幕可用工作区宽度:<span class='data'>"+screenAvailWidth+"px</span><br>";
Str+="</p>"
document.write(Str);
}
但这最多只能给我的出宽,而不能给出合适的高。
请教大家有没有什么方法。
我在网上搜索到了这个:
function displayScreenSize()
{
var bodyWidth =document.body.clientWidth; //网页可见区域宽
var bodyHeight =document.body.clientHeight; //网页可见区域高
var bodyWidthWithBorder =document.body.offsetWidth; //网页可见区域宽(包括边线的宽)
var bodyHeightWithBorder=document.body.offsetHeight; //网页可见区域高(包括边线的宽)
var bodyWidthWithScroll =document.body.scrollWidth; //网页正文全文宽
var bodyHeightWithScroll=document.body.scrollHeight; //网页正文全文高
var bodyTopHeight =document.body.scrollTop; //网页被卷去的上边距
var bodyLeftWidth =document.body.scrollLeft; //网页被卷去的左边距
var windowTopHeight =window.screenTop; //网页正文部分上边距
var windowLeftWidth =window.screenLeft; //网页正文部分左边距
var screenHeight =window.screen.height; //屏幕分辨率的高
var screenWidth =window.screen.width; //屏幕分辨率的宽
var screenAvailHeight =window.screen.availHeight; //屏幕可用工作区高度
var screenAvailWidth =window.screen.availWidth; //屏幕可用工作区宽度
var Str="<p>";
Str+="网页可见区域宽:<span class='data'>"+bodyWidth+"px</span><br>";
Str+="网页可见区域高:<span class='data'>"+bodyHeight+"px</span><br>";
Str+="网页可见区域宽(包括边线的宽):<span class='data'>"+bodyWidthWithBorder+"px</span><br>";
Str+="网页可见区域高(包括边线的宽):<span class='data'>"+bodyHeightWithBorder+"px</span><br>";
Str+="网页正文全文宽:<span class='data'>"+bodyWidthWithScroll+"px</span><br>";
Str+="网页正文全文高:<span class='data'>"+bodyHeightWithScroll+"px</span><br>";
Str+="网页被卷去的上边距:<span class='data'>"+bodyTopHeight+"px</span><br>";
Str+="网页被卷去的左边距:<span class='data'>"+bodyLeftWidth+"px</span><br>";
Str+="网页正文部分上边距:<span class='data'>"+windowTopHeight+"px</span><br>";
Str+="网页正文部分左边距:<span class='data'>"+windowLeftWidth+"px</span><br>";
Str+="屏幕分辨率的高:<span class='data'>"+screenHeight+"px</span><br>";
Str+="屏幕分辨率的宽:<span class='data'>"+screenWidth+"px</span><br>";
Str+="屏幕可用工作区高度:<span class='data'>"+screenAvailHeight+"px</span><br>";
Str+="屏幕可用工作区宽度:<span class='data'>"+screenAvailWidth+"px</span><br>";
Str+="</p>"
document.write(Str);
}
但这最多只能给我的出宽,而不能给出合适的高。
请教大家有没有什么方法。
解决方案 »
- gridview有一列根据数据库中的值为0或为1而显示不同内容,怎么实现?
- .ascx引用文件传参数
- log4net不能记录日志
- 页面使用MsChart的排版问题
- 如何判断datagrid中 checkbox被选中的个数??
- 没有找到适合的方法来重写问题,改写自Scott Mitchell的代码
- 关于decimal小数不显示的问题
- datagrid 页角的使用
- 菜鸟问题,函数返回的数据类型?
- 一个时间判断问题没办法了100分求解决办法!!!!!!
- 大家好小弟现在问个小问题哦我想在服务器端执行一个外部的程序怎么写啊?
- 急急急!在线等!ASP.NET做了一个程序,里面使用了TreeView控件,但每次点击TreeView里的链接时IE都会提示“当前站点正在试图打开具有不
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
} // for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}