You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在自定义HTML块中使用URL查询字符串(Query String)参数

你可以通过在自定义HTML块中内嵌JS解析URL查询参数的方式实现需求,具体实现代码如下:

<div id="content-wrap">{blah}</div>
<script>
// 读取URL查询参数
const queryParams = new URLSearchParams(window.location.search)
const blahValue = queryParams.get('blah') || ''
// 替换占位符
const container = document.getElementById('content-wrap')
container.textContent = container.textContent.replace('{blah}', blahValue)
</script>

按照上述代码修改你的自定义HTML块内容后,访问地址https://your-site/page1/?blah=hello时,div内容就会自动渲染为<div>hello</div>。

注意事项

  • 如果你的blah参数包含HTML标签需要渲染,可将textContent替换为innerHTML,但要注意防范XSS注入风险
  • 可根据需求调整默认值,将queryParams.get('blah') || ''中||后的内容替换为你需要的默认展示值即可

内容的提问来源于stack exchange,提问作者sten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 05:15:04