if (document.documentElement && document.documentElement.scrollTop) { t = document.documentElement.scrollTop;//滚动条的顶端 l = document.documentElement.scrollLeft;//滚动条的左端 w = document.documentElement.scrollWidth;//滚动条的宽度,也就是页面的宽度 h = document.documentElement.scrollHeight;//滚动条的高度 } else if (document.body) { t = document.body.scrollTop; l = document.body.scrollLeft; w = document.body.scrollWidth; h = document.body.scrollHeight; } return { t: t, l: l, w: w, h: h }; }
2:获得视图浏览器的宽度高度
代码如下:
function getPageWidth(){ var pageWidth = window.innerWidth; if (typeof pageWindth != "number") { if (document.compatMode == "CSS1Compat") { pageWidth = document.documentElement.clientWidth; } else { pageWidth = document.body.clientWidth; } } return pageWidth; }
function getPageHeight(){ var pageHeight = window.innerHeight; if (typeof pageWindth != "number") { if (document.compatMode == "CSS1Compat") { pageHeight = document.documentElement.clientHeight; } else { pageHeight = document.body.clientHeight; } } return pageHeight; }
3:获得当前浏览器型号 名字
代码如下:
function(){ var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
//动态添加Element,所有的浏览器都可以实现 var newnode=document.createElement("input"); newnode.type="button"; newnode.value="sixth"; //在IE中可以还这么实现 var newnode= document.createElement("");