Javascript to detect mobile browser screen width?

前端 未结 5 533
执念已碎
执念已碎 2021-02-05 15:47

i used screen.width to get the width of the browser. it worked fine with iphone safari but didn\'t work in android phone(it showed 800 width for android browser).

Is the

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 16:12

    For those interested in getting the width values of the browser, I tested several options:

    I am using bootstrap 3 and the ONLY solution matching the bootstrap 3 breakpoints with both IE and Chrome was :

    window.innerWidth 
    

    Here are the results with 1200px window with:

    Chrome

    $( window ).width(): 1183
    $( document ).width():1183
    screen.width: 1536
    $( window ).innerWidth():1183
    $( document ).innerWidth():1183
    window.innerWidth: 1200
    $( document ).outerWidth():1183 
    window.outerWidth: 1216
    document.documentElement.clientWidth: 1183 
    

    Internet Explorer 10

    $( window ).width(): 1200
    $( document ).width():1200
    screen.width: 1536
    $( window ).innerWidth():1200
    $( document ).innerWidth():1200
    window.innerWidth: 1200
    $( document ).outerWidth():1200
    window.outerWidth: 1214
    document.documentElement.clientWidth: 1200
    

提交回复
热议问题