【问题标题】:Javascript ignores # in urlJavascript 忽略 url 中的 #
【发布时间】:2016-06-19 03:01:08
【问题描述】:

我试图在域之后提取 url。根据这个question,可以通过调用window.location.pathname,但在我的网址http://domain:host/something#random=123 中,它会删除# 之后的所有内容。还有什么比拆分或正则表达式更好的吗?

在代码中:

window.location.pathname("http://domain:host/something#random=123")

返回/something

期望的行为

window.location.unknownMethodToMe("http://domain:host/something#random=123")

应该返回/something#random=123

提前致谢。

【问题讨论】:

标签: javascript


【解决方案1】:

尝试使用location.hash,它应该返回#random=123

【讨论】:

  • 所以为了实现我想要的,我必须写这样的东西:window.location.pathname(url) + window.location.hash?
  • 如果window.location.pathname返回/something,那么您应该能够使用location.hash检索#random=123
猜你喜欢
  • 1970-01-01
  • 2021-09-27
  • 2012-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-21
相关资源
最近更新 更多