从URL中提取 - 长URL

时间:2015-02-19 12:00:33

标签: javascript url

我目前正在尝试从ReturnUrl中提取= ...我想使用javascript从下面的链接中提取URL。有人可以帮忙吗?

http://testdealbuilderCCMS/questionnaire.aspx?db_template_reference=Construction: Westfield Services Agreement&ContractDescription=Facilities Contract&NatureServices=FACILITIES&SiteDescription=Retail Units&ThirdPartyAgreementsList=&ServiceFee=1000&ReturnUrl=http://localhost:4965&launcher.aspx?directLink=PX&caseKey=7ccef65756504a79bc3a4a6687c0d9555e519ec9079241c9944c6a523704&PXid=

1 个答案:

答案 0 :(得分:1)

这里有很多边缘情况会导致失败。所以要小心,只有当你的字符串总是以ReturnURL参数结尾时才使用它。

在字符串中查找ReturnURL=的位置,然后从ReturnURL=位置+ ReturnURL=长度获取子字符串,直至结束。

http://jsfiddle.net/3hvajedg/1/

the_string = 'http://testdealbuilderCCMS/questionnaire.aspx?db_template_reference=Construction: Westfield Services Agreement&ContractDescription=Facilities Contract&NatureServices=FACILITIES&SiteDescription=Retail Units&ThirdPartyAgreementsList=&ServiceFee=1000&ReturnUrl=http://localhost:4965&launcher.aspx?directLink=PX&caseKey=7ccef65756504a79bc3a4a6687c0d9555e519ec9079241c9944c6a523704&PXid=';

alert(the_string.substring((the_string.indexOf('ReturnUrl=')+'ReturnUrl='.length)));