获取链接网址的特定部分 [英] Get specific part of url of a link
本文介绍了获取链接网址的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取页面上链接的第三个和第四个斜杠之间的网址的特定部分。
I want to get a specific part of a url between the third and fourth slashes of a link on the page.
编辑:对不起我不认为我很清楚第一次,我的意思是在网页上找到网址链接的特定部分。
Sorry I don't think I was clear the first time, I meant getting the specific part of the url OF A LINK found on the page.
推荐答案
var getSegment = function (url, index) {
return url.replace(/^https?:\/\//, '').split('/')[index];
}
用法:
getSegment("http://domain.com/a/b/c/d/e", 4); // "d"
replace
确保协议后的前两个斜杠( http
或 https
)不要数。
The replace
makes sure that the first two slashes after the protocol (http
or https
) don't count.
这篇关于获取链接网址的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文