如何使用 JavaScript 代码获取浏览器宽度? - How to get browser width using JavaScript code?

问题:

I am trying to write a JavaScript function to get the current browser width.我正在尝试编写一个 JavaScript 函数来获取当前浏览器的宽度。

I found this one:我找到了这个:

javascript:alert(document.body.offsetWidth);

But its problem that it fail if the body has width 100%.但它的问题是,如果主体的宽度为 100%,它就会失败。

Is there any other better function or a workaround?还有其他更好的功能或解决方法吗?


解决方案:

参考一: https://en.stackoom.com/question/4MDf
参考二: https://stackoom.com/question/4MDf
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章