在 Tritium (Moovweb SDK) 中向 URL 添加查询参数的最佳实践是什么?寻找在您不知道 URL 是否有“?”的情况下有效的东西。和其他查询参数已经。
问问题
267 次
2 回答
3
Here's a short snippet of Tritium that should help you out in your Moovweb project. Just replace the "query_param=true" bit with the query parameter you want to add.
It selects the href
of every a
tag, then looks for any existing query parameters (by looking for a "?" in the href). If there are some existing, it just appends the new query parameter. If there are no existing query parameters on the href, it uses the ? to add one to the URL.
$q = "query_param=true"
$("//a[@href]") {
%s = fetch("./@href")
match(%s) {
with(/\?/) {
attribute("href", %s + "&" + $q)
}
else() {
attribute("href", %s + "?" + $q)
}
}
log(%s)
}
(You could also turn that into a function if you wanted!)
于 2013-03-29T23:06:20.750 回答
1
我认为很快就会有一个新的 URL 范围,这样你就可以更轻松地做这样的事情了!
于 2013-04-08T16:01:34.223 回答