mui封裝做好的手機版網站為apk

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.