Get browser window width including scrollbar

后端 未结 4 997
粉色の甜心
粉色の甜心 2020-12-15 04:09

I tried to get browser window width with $(window).width();. On IE 10, it does return the full browser width, include the scroll bar. However, on Firefox and Ch

相关标签:
4条回答
  • 2020-12-15 04:11

    window.innerWidth seems to be the correct answer when needed for responsive design

    0 讨论(0)
  • 2020-12-15 04:17

    This will get the full Window's width:

     window.outerWidth
    

    NOTE: jQuery's outerWidth() doesn’t work on $(window)

    0 讨论(0)
  • 2020-12-15 04:32

    window.innerWidth will give the width of the HTML and the scrollbar. This value is the value used for device width breakpoints when using media queries in CSS. Essentially, window.innerWidth is equal to the calculated CSS unit 100vw. However, window.outerWidth will give you the width of the entire window.

    For example, if you had Chrome's Dev Tools open inside of the browser, window.outerWidth would be the width of the webpage + scroll bar + Chrome's Dev Tools inspector. While window.innerWidth would return the width of just the webpage + scroll bar.

    0 讨论(0)
  • 2020-12-15 04:34

    The first answer was close, but upon further inspection it is a bit more complicated. The body.clientWidth is the width excluding the scrollbars. The window.outerWidth is the width including the scrollbars and other window elements like the window border. The window.innerWidth is the actual width of the window, including scrollbars, but not including the window border.

    enter image description here

    0 讨论(0)
提交回复
热议问题