js 获取当前网址/项目地址
2017-08-18 10:34
239 查看
// 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 函数不能在任何浏览器兼容
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 函数不能在任何浏览器兼容
相关文章推荐
- js获取当前页面的网址域名地址
- JS获取当前网址,JS获取当前域名URL ,JS获取网站完整路径页面地址
- JS获取当前网址、主机地址项目根路径
- JS获取当前网址,JS获取当前域名URL ,JS获取网站完整路径页面地址
- JS获取当前网址、主机地址项目根路径
- JS获取当前网址、主机地址项目根路径
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
- js如何准确获取当前页面url网址信息
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
- struts2项目中用Js获取URL地址参数
- js/jquery获取当前页面URL地址并判断URL字符串中是否包含某个具体值(获取URL的?或者#)
- js如何准确获取当前页面url网址信息
- js获取当前网址与来路IP 并应用到商务通统计来路
- [zz]js获取当前详细网址
- JS获取当前URL地址
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
- js获取当前url地址的参数
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
- js 获取当前URL地址
- js中获取当前项目名等