【问题标题】:"How can I get the URL parameters on my landing page <a link='?example=id'> attribute"“如何在我的着陆页 <a link='?example=id'> 属性上获取 URL 参数”
【发布时间】:2019-12-31 00:47:26
【问题描述】:

“我正在使用着陆页 https://example.com/?ad={{ad_set}} 我试图获取我在着陆页上使用的链接的 URL 参数,格式为 https://example.com/?广告={{ad_set}}'>

任何人都可以对我如何在着陆页链接属性上传递 URL 字符串值有任何建议吗? "

【问题讨论】:

  • 嗨。到目前为止,您尝试过什么?
  • 您是否尝试以编程方式从 URL 中获取 ad_set 值?
  • @Nomz 我需要在链接属性中添加这个值

标签: javascript html string url hyperlink


【解决方案1】:

可以使用

获取URL的查询参数
window.location.search.substring(1);

它会返回'?'之后的所有值从网址。

或者如果你想要一个特定的值,你甚至可以使用(参考你提到的 URL 的例子:https://example.com/?ad=123)

var urlParams = new URLSearchParams(location.search);
urlParams.get('ad'); 

它将返回 123。

希望这会有所帮助。

【讨论】:

  • 如果我使用的是example.com/…>
  • 那么,基本上,您需要有关完整 URL 参数的信息吗?还是只是查询参数?
  • window.location.pathname 将返回当前页面的路径和文件名。
猜你喜欢
  • 1970-01-01
  • 2019-01-22
  • 2013-01-18
  • 2023-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多