gpt4 book ai didi

javascript - 解码编码参数中的 url (returnUrl)

转载 作者:行者123 更新时间:2023-12-03 00:14:57 25 4
gpt4 key购买 nike

我想使用多次参数“returnUrl”来检索 url 中的一些参数。

示例:

HTTPS://force.com?positionId=a0w0X000007HjBuQAK&lang=fr&mediaChannel=a0o0X00000EGQ5TQAX&returnUrl=https%253A%2F%2force.com%2Fcxsrec__cxsSearchDetail%3Fid%3Da0w0X000007HjBuQAK%26lang%3Dfr%26mediaChannel%3Da0o0X00000EGQ5TQAX%26returnUrl%3Dhttps%253A%2F%2force.com%2Fcxsrec__cxsSearch%253Flang%253Dfr%2526mediaChannel%253Da0o0X00000EGQ5TQA%2526 site%253DFrance%2526hcFilter%253Da0Z0X00000XiFF3UAN%252Ca0Z0X00000XiUqTUAV%2526orderBy%253DPosition_name__c%2526orderDir%253Dasc%2526mediaChannel%253Da0o0X00000EGQ5TQAX%26lang%3Dfr%26mediaChannel%3Da0o0X00000EGQ5TQAX’

?...returnUrl%3Dhttps%253A%2F%2force.com%2Fcxsrec__cxsSearch%253Flang%253Dfr%2526mediaChannel%253Da0o0X00000EGQ5TQA%2526网站%253DFrance%2526hc过滤器。 ..

我想获取参数site的值。

我尝试使用 decodeURI 函数,然后使用 searchParams.get("site")decodeURI 它没有解码 <之后的参数强>returnUrl。

还有其他函数可以做到这一点吗?

最佳答案

您需要decodeURIComponent() .

我删除了网址中 site 之前的空格:

const url1 = new URL('https://force.com?positionId=a0w0X000007HjBuQAK&lang=fr&mediaChannel=a0o0X00000EGQ5TQAX&returnUrl=https%253A%2F%2force.com%2Fcxsrec__cxsSearchDetail%3Fid%3Da0w0X000007HjBuQAK%26lang%3Dfr%26mediaChannel%3Da0o0X00000EGQ5TQAX%26returnUrl%3Dhttps%253A%2F%2force.com%2Fcxsrec__cxsSearch%253Flang%253Dfr%2526mediaChannel%253Da0o0X00000EGQ5TQA%2526site%253DFrance%2526hcFilter%253Da0Z0X00000XiFF3UAN%252Ca0Z0X00000XiUqTUAV%2526orderBy%253DPosition_name__c%2526orderDir%253Dasc%2526mediaChannel%253Da0o0X00000EGQ5TQAX%26lang%3Dfr%26mediaChannel%3Da0o0X00000EGQ5TQAX');
const params1 = new URLSearchParams(url1.search);
const returnUrl = params1.get('returnUrl');

const url2 = new URL(decodeURIComponent(returnUrl));
const params2 = new URLSearchParams(url2.search);
const site = params2.get('site');

console.log(site);

查看 encodeURIComponent() description 中的一些详细信息

关于javascript - 解码编码参数中的 url (returnUrl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54561259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com