[英]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.