如何使用 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章