MUI在子页面操作父页面案例!!!
先看子页面
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link href="css/mui.min.css" rel="stylesheet" />
</head>
<body>
<div class="mui-content">
i am child
</div>
</body>
<script src="js/mui.min.js"></script>
<script type="text/javascript">
mui.init();
mui.plusReady(function(){
//在H5+加载完后执行,用了plus ready()
var vmIndex = plus.webview.getLaunchWebview(); // 要操作的父页面,这里是写的是入口页面
vmIndex.evalJS('edithello();');
})
</script>
</html>
再来看看父页面。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<link href="css/mui.min.css" rel="stylesheet"/>
<body>
<button type="button" class="mui-btn mui-btn-primary" οnclick="allwebview()">allwebview</button>
<a href="javascript:openchild();" class="mui-btn mui-btn-primary">open child</a>
<div id="txt"></div>
<script src="js/mui.min.js"></script>
<script type="text/javascript" charset="utf-8">
mui.init();
/*document.getElementById("#openchild").on("tap",function(){
plus.webview.open("child.html","child",{},"slide-in-right")
});*/
function openchild(){
plus.webview.open("child.html","child",{},"slide-in-right");
};
// 子页面要父页面执行的事件
function edithello(){
document.getElementById("txt").innerText= "hellochild";
}
</script>
</head>
</body>
</html>