javascript - 如何取不同手机浏览器的实际可用高度?
PHP中文网
PHP中文网 2017-04-11 08:56:38
[JavaScript讨论组]

我用js代码window.screen.availHeight取屏幕的高度,然后拼凑内容来让页面满屏显示。
测试发现不同手机浏览器有自己的地址栏、状态栏等,window.screen.availHeight取到的屏幕高度也包括了这两者,导至本来希望满屏显示的内容溢出到屏幕下方需要下拉滚动条才能看到。
请问怎么才能让页面在任何手机浏览器上都能满屏显示?

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(2)
伊谢尔伦
function getBrowserInterfaceSize() {
    var pageWidth = window.innerWidth;
    var pageHeight = window.innerHeight;

    if (typeof pageWidth != "number") {
        //在标准模式下面
        if (document.compatMode == "CSS1Compat" ) {
            pageWidth = document.documentElement.clientWidth;
            pageHeight = document.documentElement.clientHeight;
        } else {
            pageWidth = document.body.clientWidth;
            pageHeight = window.body.clientHeight;
        }
    }

    return {
        pageWidth: pageWidth,
        pageHeight: pageHeight
    }
}
ringa_lee

我感觉还是用meta标签让浏览器直接全屏比较合适

<!-- 启用 WebApp 全屏模式 -->
<meta name="apple-mobile-web-app-capable" content="yes" /> 

<!-- uc强制竖屏 -->
<meta name="screen-orientation" content="portrait">

<!-- UC强制全屏 --> 
<meta name="full-screen" content="yes">

<!-- UC应用模式 --> 
<meta name="browsermode" content="application">

<!-- QQ强制竖屏 -->
<meta name="x5-orientation" content="portrait">

<!-- QQ强制全屏 -->
<meta name="x5-fullscreen" content="true">

<!-- QQ应用模式 -->
<meta name="x5-page-mode" content="app">

参考常用meta整理

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号