您的位置:首页 > Web前端 > JavaScript

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 函数不能在任何浏览器兼容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: