【问题标题】:Editing window.location.hash will cause the query string to be removed编辑 window.location.hash 会导致查询字符串被移除
【发布时间】:2015-01-11 23:18:01
【问题描述】:

我有以下字符串:

http://example.com/?phrase=samplePhrase

当我点击某个元素时,URL 会收到这样的哈希编辑:

#show/item

使用这个 javascript 代码:

window.location.hash =  "/" + "show" + "/" + "item";

但我只想将此哈希编辑附加到当前 URL 的任何内容。所以有:

http://example.com/?phrase=samplePhrase#show/item

但它首先删除查询字符串是什么,然后使 url 像这样:

http://example.com/#/show/item

有人可以帮忙吗?

【问题讨论】:

    标签: javascript jquery hash


    【解决方案1】:

    如果您需要从 URL 中获取参数,您应该可以执行以下操作:

    var params = window.location.search;
    window.location.hash =  params + "#" + "show" + "/" + "item";
    

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 2018-10-21
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 2013-08-11
      • 2015-02-16
      相关资源
      最近更新 更多