Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k 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 Answer

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]。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...