【发布时间】:2018-11-07 11:34:37
【问题描述】:
我见过有example.org/#Parameter 形式的url 参数的网站,而不是example.org/?parameter=123。我不是在谈论将页面滚动到元素 id 的 url,而是在 express.js 中提取 url 中 # 之后的值。我该怎么做?
【问题讨论】:
-
浏览器不向服务器发送URL的hash部分。
我见过有example.org/#Parameter 形式的url 参数的网站,而不是example.org/?parameter=123。我不是在谈论将页面滚动到元素 id 的 url,而是在 express.js 中提取 url 中 # 之后的值。我该怎么做?
【问题讨论】:
你可以使用全局变量window.location.hash来获取某个URL的哈希变量的值。
此外,您还可以使用以下 jquery 函数捕获哈希值变化:
$(window).on('hashchange', function() {
//some code
});
编辑:
据了解,window.location.hash 永远不会发送到服务器/中间件,因此无法在 express 上获取此参数。
您应该改用查询字符串参数 (example.org?parameter=123)。
【讨论】: