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]);
		}
	}
	
}
複製代碼
相關文章
相關標籤/搜索