如何在TMS Web Core中设置URL查询字符串参数?
TMS Web Core设置URL查询参数的内置方法问题
我可以通过WebLib.WebTools单元的GetQueryParam函数获取当前URL参数,但原以为对应的设置参数函数是SetQueryParam,实际该函数并不存在。
运行以下代码时:
SetQueryParam('first_name', 'Shaun'); SetQueryParam('last_name', 'Roselt');
会报错:
identifier not found "SetQueryParam"
请问用Delphi代码设置查询参数的函数及对应单元是什么?
补充:我目前使用自行编写的函数更新URL参数,代码如下:
procedure SetQueryParam(key, value, url: String); begin asm if (!url) url = window.location.href; let re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),hash; if (re.test(url)) if (typeof value !== 'undefined' && value !== null) url = url.replace(re, '$1' + key + "=" + value + '$2$3'); else { hash = url.split('#'); url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, ''); if (typeof hash[1] !== 'undefined' && hash[1] !== null) url += '#' + hash[1]; } else if (typeof value !== 'undefined' && value !== null) { const separator = url.indexOf('?') !== -1 ? '&' : '?'; hash = url.split('#'); url = hash[0] + separator + key + '=' + value; if (typeof hash[1] !== 'undefined' && hash[1] !== null) url += '#' + hash[1]; } window.history.pushState({ path: url }, '', url); end; end;
调用方式:
SetQueryParam('first_name', 'Shaun'); SetQueryParam('last_name', 'Roselt');
该代码可实现需求,但混合了JavaScript与Delphi代码,较为繁琐。想问下TMS Web Core是否有内置的纯Delphi方法用于设置URL参数?
内容的提问来源于stack exchange,提问作者Shaun Roselt
相关产品推荐
相关产品推荐

