use*_*132 13 javascript android resolution
我使用screen.width来获取浏览器的宽度.它与iphone safari工作正常,但在Android手机中没有工作(它显示了800浏览器的宽度).
是否有任何兼容的方式来获得屏幕宽度.我不想使用UserAgent来检查它的移动浏览器.我想使用javascript,逻辑应该包括屏幕宽度.
您可以尝试使用此网址来检测屏幕尺寸并应用 CSS 样式
或者
<script type="text/javascript">
function getWidth()
{
xWidth = null;
if(window.screen != null)
xWidth = window.screen.availWidth;
if(window.innerWidth != null)
xWidth = window.innerWidth;
if(document.body != null)
xWidth = document.body.clientWidth;
return xWidth;
}
function getHeight() {
xHeight = null;
if(window.screen != null)
xHeight = window.screen.availHeight;
if(window.innerHeight != null)
xHeight = window.innerHeight;
if(document.body != null)
xHeight = document.body.clientHeight;
return xHeight;
}
</script>
screen.height shows the height of the screen
screen.width shows the width of the screen
screen.availHeight shows height but removes the interface height like taskbar, and browser menu etc.
screen.availWidth same as above,instead gives available width
Run Code Online (Sandbox Code Playgroud)