JS获取当前网址 项目名 主机

来源:互联网 发布:photoshop软件购买 编辑:程序博客网 时间:2024/05/16 02:49
// 1 获取当前网址,如:localhost:8080/Tmall/index.jsp
var currentWebsite=window.document.location.href; 

// 2 获取主机地址之后的目录, 如:/Tmall/index.jsp 
var pathName=window.document.location.pathname; 
var pos=currentWebsite.indexOf(pathName); 

// 3 获取主机地址,如://localhost:8080 
var localhostPaht=currentWebsite.substring(0,pos); 

// 4 获取带"/"的项目名,如:/Tmall 
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 
0 0
原创粉丝点击