我有以下字符串:
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
有人可以帮忙吗?
答案 0 :(得分:1)
如果您需要从URL中获取参数,您应该可以执行以下操作:
var params = window.location.search;
window.location.hash = params + "#" + "show" + "/" + "item";