Javascript 获取不包括工具栏和菜单大小的浏览器宽度和高度
我需要一个Js/JQuery脚本,它返回我浏览器的可用宽度和高度,不包括菜单栏和工具栏大小,我使用一个脚本,但它似乎返回宽度/高度,包括工具栏等 下面是我使用的脚本Javascript 获取不包括工具栏和菜单大小的浏览器宽度和高度,javascript,jquery,browser,Javascript,Jquery,Browser,我需要一个Js/JQuery脚本,它返回我浏览器的可用宽度和高度,不包括菜单栏和工具栏大小,我使用一个脚本,但它似乎返回宽度/高度,包括工具栏等 下面是我使用的脚本 <script type="text/javascript" > var winWidth = 0, winHeight = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE winWidth
<script type="text/javascript" >
var winWidth = 0, winHeight = 0;
if (typeof (window.innerWidth) == 'number') {
//Non-IE
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards compliant mode'
winWidth = document.documentElement.clientWidth;
winHeight = document.documentElement.clientHeight;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 compatible
winWidth = document.body.clientWidth;
winHeight = document.body.clientHeight;
}
</script>
变量winWidth=0,winHeight=0;
if(typeof(window.innerWidth)=‘number’){
//非IE
winWidth=window.innerWidth;
winHeight=window.innerHeight;
}else if(document.documentElement&(document.documentElement.clientWidth | | document.documentElement.clientHeight)){
//IE 6+处于“标准兼容模式”
winWidth=document.documentElement.clientWidth;
winHeight=document.documentElement.clientHeight;
}else if(document.body&(document.body.clientWidth | | document.body.clientHeight)){
//IE4兼容
winWidth=document.body.clientWidth;
winHeight=document.body.clientHeight;
}
有人对此有任何线索吗?
谢谢
Meghana您的代码应该返回浏览器窗口的可用大小。在我的例子中,在1920x1200显示器上,我得到1920x1106。我的任务栏有40像素高,因此窗口的标题栏只有54px。使用jQuery,您可以获得以下内容:
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
尝试:
$('#btn1')。单击(函数(){
警报($(窗口).width());
});
看你说得对。。。我再次检查了我的代码,它返回给我浏览器高度/宽度,不包括工具栏等。实际上,我有用户的屏幕分辨率,需要浏览宽度/高度。我需要做一些与用户的屏幕分辨率成比例的计算,但它并没有给我返回正确的结果。现在我知道了。。。我需要浏览器窗口的宽度/高度,包括工具栏等。。。与我当前的帖子正好相反:)。所以我应该再发一篇帖子。。如果你有什么想法,也请帮我。再次感谢。
screen.width
和screen.height
将提供用户的屏幕分辨率。谢谢@Mathboy,但我知道我的帖子如果不符合我的要求。。。我正在添加新的帖子。。。如果你有任何想法,请帮助我:)谢谢@Bui-Cuong,但我知道我的帖子如果不符合我的要求。。。我正在添加新的帖子。。。如果你有任何想法,请帮助我:)
<input type='button' id='btn1' value='test'/>
$('#btn1').click(function(){
alert($(window).width());
});