用javascript / jquery点击DOM元素后,在地址栏中更改网址 [英] Change URL in address bar after click on DOM element with javascript/jquery
本文介绍了用javascript / jquery点击DOM元素后,在地址栏中更改网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$('#p $) ('change',function(){
$ .ajax(options);
//改变浏览器URL
});
例:
之前: http://somepage.com/filters
后: http://spagepage.com / filters?type = apartment
解决方案
是的,这可以通过历史API 。 history.pushState
和 历史记录。 replaceState
让您指定一个新的URL,例如:
history.pushState(null ,null,filters?type = apartment);
URL以通常的方式解析。
浏览器支持很好,除了IE9及更早版本。
is there any way to change the URL in browser without reloading page after click a DOM element?
$('#filter_form').on('change', function () {
$.ajax(options);
//change the browser URL
});
Ex:
Before: http://somepage.com/filters
After: http://somepage.com/filters?type=apartment
解决方案
Yes, this is possible with the history API. Both history.pushState
and history.replaceState
let you specify a new URL, e.g.:
history.pushState(null, null, "filters?type=apartment");
The URL is resolved in the usual way.
Browser support is good, other than IE9 and earlier.
这篇关于用javascript / jquery点击DOM元素后,在地址栏中更改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文