mui项目总结第1篇---窗口的获取以及关闭

关于获取webview(窗口间关系)的方法

1.获取指定页面ID的webview

plus.webview.getWebviewById('为页面设置的id值');
复制代码

2.获取当前页面的webview

plus.webview.currentWebview();
复制代码
var ws=plus.webview.currentWebview();//获取当前页面所属的Webview窗口对象

console.log( "窗口标识: "+ws.id );

console.log( "当前Webview窗口:"+ws.getURL() );
复制代码

3.获取当前页面的父级

plus.webview.currentWebview().opener();
复制代码

4.获取全部的可视的webview窗口

plus.webview.all();
复制代码

5.获取应用显示栈顶的WebviewObject窗口对象

plus.webview.getTopWebview();
复制代码

关闭窗口

注意:方法要写在plusready方法内部html

document.addEventListener("plusready", onPlusReady, false);
			
function onPlusReady(){       
	var curr = plus.webview.currentWebview();   //获取当前页面
	var wvs = [];       //空数组用来储存已经获取的窗口
	if(plus.webview.getWebviewById('my_vip0.html')){
	    //首先判断该页面否已经打开不然不添加
		wvs.push(plus.webview.getWebviewById('my_vip0.html'));
	}
	if(plus.webview.getWebviewById('my_vip1.html')){
	    //首先判断该页面否已经打开不然不添加
		wvs.push(plus.webview.getWebviewById('my_vip1.html'));
	}
	if(plus.webview.getWebviewById('my_vip2.html')){
	    //首先判断该页面否已经打开不然不添加
		wvs.push(plus.webview.getWebviewById('my_vip2.html'));
	}
	console.log(wvs);
	for (var i = 0,len = wvs.length; i < len; i++) {
  		//关闭除当前页面外的其余页面
  		//关闭方法一
  		if (wvs[i].getURL() != curr.getURL()){
			plus.webview.close(wvs[i],"none");
  		}
  		//关闭除指定页面外的其余页面
  		//key 能够是指定页面名称或者其余关键字
  		//关闭方法二
		if (wvs[i].getURL().indexOf("Key") == -1){
			plus.webview.close(wvs[i]);
		}
	}
	
}
复制代码
相关文章
相关标签/搜索