简体   繁体   中英

How to find out when window.location changes

I have an ajax function that performs a filter and then changes the url.

How would I do the equivalent of the following:

$(window.location).change(function() {
    alert('hello');
})

You would probably have a look at the history API. You can use the onhashchange event to detect that change.

$(window).on('hashchange', function() {
    alert('hello');
});

如果更改位置,浏览器停止所有脚本并且不触发更改功能,则在使用更改位置时只能使用文档的卸载事件,请在此处进行检查http://api.jquery.com/unload/ ,如果仅更改书签,然后仅处理hashchange事件,您可以在http://benalman.com/projects/jquery-hashchange-plugin/中找到示例jquery插件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM