如何使用JavaScript代码获取浏览器宽度? [英] How to get browser width using javascript code?
本文介绍了如何使用JavaScript代码获取浏览器宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个javascript函数来获取当前的浏览器宽度。
我找到了这个:
javascript:alert(document.body.offsetWidth);
但是它的问题是如果主体宽度为100%就会失败
解决方案
这是一个在屁股疼痛。我建议您跳过废话并使用 jQuery ,这样您只需执行 $(window).width()
。
I am trying to write a javascript function to get the current browser width.
I found this one:
javascript:alert(document.body.offsetWidth);
But its problem that it fail if the body has width 100%
There is any other better function or a work around?
解决方案
It's a pain in the ass. I recommend skipping the nonsense and using jQuery, which lets you just do $(window).width()
.
这篇关于如何使用JavaScript代码获取浏览器宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文