需求:要在A界面中的卡头(头布局)和卡位(底部tab)中加载webView呈现内容,在webView界面中获取A界面头布局的title id和一个图片id :
代码如下:
A界面中卡头,卡头布局(头布局)的代码:
mui.init({
swipeBack: false,
statusBarBackground: '#82D1C5',
gestureConfig: {
tap: true,
},
subpages: [{
id: 'list.html',
url: 'list.html',
styles: {
top: '45px',
bottom: '50px',
bounce: 'vertical'
},
extras:{
divimg:'footer_left_div_id',
title:'header_title_span'
}//额外扩展参数
}]
});
//在加载的webView界面中获取2个相应的id:
<script type="text/javascript">
/*dom准备就绪后,调用此事件*/
function plusReady(){
mui.plusReady(function(){
var url=plus.webview.currentWebview().getURL();
console.log("获取当前页面webView URL:=="+url);
//获取模板界面中传递的参数
var self = plus.webview.currentWebview();
var divimg = self.divimg;
var title = self.title;
//持久化保存
localStorage.setItem("current_page_url",url);
localStorage.setItem("divimg",divimg);
localStorage.setItem("title",title);
console.log("传递过来的div img id:=="+divimg);
console.log("传递过来的title id:=="+title);
});
}
if(window.plus){
plusReady();
console.log("window.plus");
}else{
document.addEventListener("plusready",plusReady,false);
console.log("plusReady");
}
</script>
打印结果如下:
plusReady at list.html:179
获取当前页面webView URL:==file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/www/list.html at list.html:157
传递过来的div img id:==footer_left_div_id at list.html:166
传递过来的title id:==header_title_span at list.html:167