[英]Change URL in address bar after click on DOM element with javascript/jquery
有什么方法可以在单击DOM元素后更改浏览器中的URL而无需重新加载页面?
$('#filter_form').on('change', function () {
$.ajax(options);
//change the browser URL
});
例如:
之前: http://somepage.com/filters
: http://somepage.com/filters
之后: http://somepage.com/filters?type=apartment
: http://somepage.com/filters?type=apartment
是的,这可以通过history API实现 。 history.pushState
和history.replaceState
允许您指定一个新URL,例如:
history.pushState(null, null, "filters?type=apartment");
该URL以通常的方式解析。
除了IE9和更早版本之外, 浏览器支持都很好 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.