zoukankan      html  css  js  c++  java
  • mui封装做好的手机版网站为apk

    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;100%;height:100%;" src="http://baidu.com/"></iframe>
        </body>

    </html>

  • 相关阅读:
    手起刀落-一起来写经典的贪吃蛇游戏
    同步、异步、回调执行顺序之经典闭包setTimeout分析
    起步
    设计模式之单例模式与场景实践
    青春是如此美好,又怎忍平凡度过
    nvm管理不同版本的node和npm
    起步
    基础
    调用wx.request接口时需要注意的几个问题
    微信小程序实现各种特效实例
  • 原文地址:https://www.cnblogs.com/niunan/p/8413010.html
Copyright © 2011-2022 走看看