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

来源:互联网 发布:mt4画线软件 编辑:程序博客网 时间:2024/06/12 00:04

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/>");



0 0