我目前正在尝试从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=

最佳答案

这里有很多边缘情况会导致失败。因此请小心,仅当您的字符串始终以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)));

关于javascript - 从URL提取-长URL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28605832/

10-12 13:46