MUI 5+plus 獲取APP根目錄

/* 
 功能:獲取App根目錄
 實例:app.getRoot()   
      當前訪問路徑:/page/index.html,結果:../
      當前訪問路徑:/page/child/index.html,結果:../../

      使用場景:app.getRoot()+"/page/child/index.html"
 */
var app = app || {};
app.getRoot = function() {
	if (window.plus) {
		return plus.io.convertLocalFileSystemURL("_www");
	} else {
		var pageUrl = window.location.pathname.replace('/項目名稱/', '');
		var levelCount = pageUrl.split('/').length;

		if (levelCount == 1) {
			return './';
		}

		var rootUrl = '';
		for (var i = 0; i < levelCount - 1; i++) {
			rootUrl += '../';
		}
		return rootUrl;
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章