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