// js 获取项目地址
var protocol = location.protocol;
var hostname = location.hostname;
var port = location.port; var pathname = location.pathname;
var basePath = protocol + "//" + hostname + ":" + port + pathname;
--------------------------------------------
// 如果项目地址结尾有 index.jsp,去掉 index.jsp
if ( basePath.indexOf( 'index.jsp' ) != -1 ) {
basePath = basePath.substr( 0, basePath.indexOf( 'index.jsp' ) );
}
---------------------------------------------
js 有 indexOf 函数,却没有 java 里那种 startsWith,endsWith 函数。
另外据说 js 中 startsWith,endsWith 函数不能在任何浏览器兼容