Javascript:获取浏览器窗口和屏幕的可用宽高

1.获取浏览器窗口的有效宽高(不包括工具栏和滚动条)

注:对于绝大部分浏览器使用window.innerWidth即可获取宽度,使用document.documentElement.clientWidth || document.body.clientWidth 为了实现对IE6,7的支持。

高度同上。

var w=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var h=window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; x=document.getElementById("screen_size"); x.innerHTML="浏览器的内部窗口宽度:" + w + ",高度:" + h + "。"2.获取屏幕的有效宽高document.write("屏幕可用尺寸,宽:" + screen.availWidth+",高:"+screen.availHeight);3.location相关(获取web服务器相关信息) document.write("web 主机的域名: "+location.hostname+"<br/>");document.write("当前页面的路径和文件名: "+location.pathname+"<br/>");document.write("web 主机的端口: "+location.port+"<br/>");document.write("所使用的 web 协议: "+location.protocol+"<br/>");document.write("当前页面的url: "+location.href+"<br/>");

,用最少的浪费面对现在

Javascript:获取浏览器窗口和屏幕的可用宽高

相关文章:

你感兴趣的文章:

标签云: