码迷,mamicode.com
首页 > 移动开发 > 详细

mui封装做好的手机版网站为apk

时间:2018-02-04 14:47:10      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:oss   window   listen   java   index   iframe   one   border   应该   

BOSS提到的一个功能,就是把已经做好的手机网站http://xxx.com/m/home/index ,想着看起来应该蛮简单,一个html页面里就一个iframe就好了,然后宽度和高度都设置为100%, 试了下,宽度没问题,就是高度的话100%是没有用的,试过在我的MX2手机上是可以100%撑开,钽是在同事的华为手机上又不能撑开了,上网搜索了一下,可以用JS来取得整个窗口的高度,下面是代码,直接写在MUI的新建 的项目中的INDEX.HTML页面就行了


<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <title></title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }
        </style>
        <script type="text/javascript">
            document.addEventListener(‘plusready‘, function() {
                //console.log("所有plus api都应该在此事件发生后调用,否则会出现plus is undefined。"
            //    var h = plus.webview.currentWebview().height; 这是错的,取不到值
                //console.log("当前页面URL:" + plus.webview.currentWebview().getURL() + " ,当前窗口高度:" + h);

            //    document.getElementById(‘frm1‘).style.height = h + "px";
            });

            function setIframeHeight(iframe) {
                if(iframe) {
                    var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
                    if(iframeWin.document.body) {
                        iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                        console.log("窗口高度:" + iframe.height);
                        document.getElementById(‘frm1‘).style.height = iframe.height + "px";
                    }
                }
            };

            window.onload = function() {
                setIframeHeight(document.getElementById(‘frm1‘));
            };
        </script>
    </head>

    <body>
        <iframe id="frm1" style="border:none;width:100%;height:100%;" src="http://baidu.com/"></iframe>
    </body>

</html>

mui封装做好的手机版网站为apk

标签:oss   window   listen   java   index   iframe   one   border   应该   

原文地址:https://www.cnblogs.com/niunan/p/8413010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!