Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

js分解url地址

http://111.111.11.11/igserver...
js怎么分解url比如
http://
219.142.81.86
/
igserver
/
ogc
/
kvp
/
TAS10R52000J49
/
WMTSServer
我要的是TAS10R52000J49这一个


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

如果是是在浏览器中,可以利用浏览器来的一些支持来加速解析,例如

var parser = document.createElement('a');
parser.href = "http://111.111.11.11:4645/igserver/ogc/kvp/TAS10R52000J49/WMTSServer?sdfdsfdsaf"

则有

 parser.protocol; // http:
 parser.hostname;  // 111.111.11.11
 parser.port;     // 4645
 parser.host;     // 111.111.11.11:4645
 parser.pathname; // /igserver/ogc/kvp/TAS10R52000J49/WMTSServer
 parser.search;   // ?sdfdsfdsaf

这里对 parser.pathname 进一步处理:

var Arrs=parser.pathname.split('/');
console.log(Arrs[4]);

即这里你想要的就是Arrs[4]。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...