问题描述
有没有办法使用javascript设置查询字符串的值?
Is there a way to set the values of a querystring using javascript?
我的页面有一个过滤器列表,点击后会改变页内结果右侧的窗格。
My page has a filter list that when clicked, it will alter the in-page results pane on the right hand side.
我正在尝试更新到url的查询字符串值,因此如果用户离开页面,则单击返回按钮,它们将返回到最后一个过滤器选择集。
I'm trying to update to the querystring values of the url, so if the user leaves the page, then clicks the "back" buttons they'll be return to the last filter selection set.
例如:
登陆:foo.html
点击1:foo.html?facets = bar
点击2:foo.html?facets = bar | baz
点击3:foo.html?facets = bar | baz | zap
For example:
Landing: foo.html
Click 1: foo.html?facets=bar
Click 2: foo.html?facets=bar|baz
Click 3: foo.html?facets=bar|baz|zap
这可能吗?
推荐答案
您可以使用Javascript更改哈希值(URL的#hash-part),但更改查询字符串意味着您必须重新加载页面。所以,不,你想做什么是不可能的。
You can use Javascript to change the hash (the #hash-part of the URL), but changing the query string means you have to reload the page. So, no, what you want to do is not possible in that way.
另一种方法是使用Javascript来改变哈希值,然后检查页面加载时的哈希值动态更改结果。您正在寻找像这样的内容。
An alternative is to use Javascript to change the hash, then check the hash on page load to change your results dynamically. You're looking for something like jQuery Address.
这篇关于如何使用Javascript设置查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!