/*取得应用根路径*/ function getContextPath() { var contextPath = document.location.pathname; var index = contextPath.substr(1).indexOf("/"); contextPath = contextPath.substr(0, index + 1); delete index; return contextPath; } /*********************************************************************** * 针对http://newbook.chaoxing.com:8082/fm/index.do?id=5 * document.location['hostname'] = newbook.chaoxing.com * document.location['host'] = newbook.chaoxing.com:8082 * document.location['port'] = 8082 * document.location['pathname'] = /fm/index.do * document.location['search'] = ?id=5 * document.location['protocol'] = http * ********************************************************************/ /*取得应用域名*/ function getDomain() { var protocal = document.location['protocol']; var host = document.location['host']; var context = getContextPath(); var result = protocal + "//" + host ; return result; }