What is the best way to check mobile screen wi开发者_JAVA百科dth using JavaScript? I've tried screen.width but get mixed results.
Modernizr would be a good tool for you to use. Have a look at the mq() function (media query). It uses the CSS @media tag to evaluate media types and screen sizes.
You can use the Javascript mobile detection method at HandsetDetection.com. Create a site profile with no redirection rules and embed the detection javascript in your page. Then you can access the HandsetDetection.width and HandsetDetection.height variables directly from javascript for screen resolution.
Hope that helps.
(Disclaimer: I work there).
精彩评论