標籤:
// #region 取虛擬目錄範例程式碼//擷取網站虛擬目錄名稱function GetVirtualDirectoryName() { var pathname = removeFirstSlash(location.pathname); var pos = pathname.indexOf(‘/‘); return pathname.substr(0, pos);}//擷取網站標題function GetHeader() { var host = removeFirstLastSlash(location.host); var dirName = GetVirtualDirectoryName(); return "http://" + host + "/" + dirName;}// #endregion // #region 擷取頂層表單// 判斷當前頁面是否是頂層頁面function getTopWindow(page) { if (page == top) { return page; } else { return getTopWindow(page.parent); }}// #endregion// #region 首尾斜杠去除// 移除首斜杠function removeFirstSlash(str) { if (isNullOrEmpty(str)) return null; if (str.toString().indexOf("/")==0) { str = str.substr(1); } return str;}// 移除尾斜杠function removeLastSlash(str) { var len = 0; if (isNullOrEmpty(str)) return null; len = str.toString().length; if (str.toString().indexOf( "/")==len-1) { str = str.substr(len-1); } return str;}// 移除首尾斜杠function removeFirstLastSlash(strValue) { if (isNullOrEmpty(strValue)) { return null; } strValue = removeFirstSlash(strValue); strValue = removeLastSlash(strValue); return strValue;}// #endregion// #region js對象是否為空白// 判斷js對象是否為空白 function isNullOrEmpty(obj) { if (obj!=null && typeof obj != "undefined" && obj.length>0) { return false; } else { return true; } }// #endregion
javascript 絕對路徑工具類