Javascript代码实例:JS获取浏览器宽度

文章简介:js获取浏览器窗口宽高及网页宽高.

js获取浏览器窗口宽高及网页宽高:

/**
/ THIRD FUNCTION
* getPageSize() by webjx.com
*
* @return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
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
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
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 = xScroll;
} else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
return arrayPageSize;
};

时间: 2024-08-04 09:14:58

Javascript代码实例:JS获取浏览器宽度的相关文章

js获取浏览器宽度 高度

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.aimeige.com.cn/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.111cn.net/ 1999/xhtml"> <head> <meta http-equiv=&q

编写跨浏览器的javascript代码必备[js多浏览器兼容写法]_javascript技巧

序号 操作 分类 IE(6.0) FireFox(2.0) Mozilla(1.5) 当前浏览器 备注 1 "." 访问tag的固有属性 OK OK OK OK 2 "." 访问tag的用户定义属性eg: <input type="checkbox" myattr="test"> OK NO NO OK 可以用getAttribute函数 替代 3 obj.getAttribute 访问tag的固有属性 OK OK

js 获取浏览器的高度和宽度信息类

网页可见区域宽: document.body.clientWidth; 网页可见区域高: document.body.clientHeight; 网页可见区域宽: document.body.offsetWidth + " (包括边线和滚动条的宽)"; 网页可见区域高:document.body.offsetHeight + " (包括边线的宽)"; 网页正文全文宽:document.body.scrollWidth; 网页正文全文高:document.body.s

JS 获取浏览器和屏幕宽高等信息代码

 这篇文章主要介绍了JS 获取浏览器和屏幕宽高等信息的具体实现,需要的朋友可以参考下 网页可见区域宽:document.body.clientWidth  网页可见区域高:document.body.clientHeight  网页可见区域宽:document.body.offsetWidth (包括边线的宽)  网页可见区域高:document.body.offsetHeight (包括边线的宽)  网页正文全文宽:document.body.scrollWidth  网页正文全文高:docu

js获取浏览器高度 窗口高度 元素尺寸 偏移属性的方法_javascript技巧

如下所示: screen.width screen.height screen.availHeight //获取去除状态栏后的屏幕高度 screen.availWidth //获取去除状态栏后的屏幕高度 一.通过浏览器获得屏幕的尺寸 二.获取浏览器窗口内容的尺寸 //高度 window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight //宽度 window.innerWidth

js获取浏览器用户信息再创建不同版本的flash组件

这是一款利用了在flash网站的代码,他是利用js获取浏览器用户信息再创建不同版本的flash组件实例,这样很好的兼容大部份主流浏览器就ok了. */ var isie  = (navigator.appversion.indexof("msie") != -1) ? true : false; var iswin = (navigator.appversion.tolowercase().indexof("win") != -1) ? true : false;

求大神用通俗语言解析下这个javascript代码以及JS中原型的具体作用。

问题描述 求大神用通俗语言解析下这个javascript代码以及JS中原型的具体作用. window.onload=function () { var oTab=new TabSwitch('div1'); }; function TabSwitch(id) { var oDiv=document.getElementById(id); this.aBtn=oDiv.getElementsByTagName('input'); this.aDiv=oDiv.getElementsByTagNam

原生JS 获取浏览器、窗口、元素等尺寸总结

一.通过浏览器获得屏幕的尺寸 screen.widthscreen.height screen.availHeight //获取去除状态栏后的屏幕高度screen.availWidth  //获取去除状态栏后的屏幕高度 二.获取浏览器窗口内容的尺寸 //高度window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight //宽度window.innerWidth || docume

JS获取各种宽度、高度的简单介绍_基础知识

有时候项目中会用到用js获取元素位置来定位元素,首先通过图片说明scrollWidth,clientWidth,offsetWidth的关系. JS获取各种宽度.高度的简单介绍: scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 scrollWidth:获取对象的滚动宽度 offsetHeight:获取对象相对于版面或由父坐标 of