I'd like to prevent jumping to an anchor on a hashchange event. I could figure out how to disable this behaviour when clicking on a link. but unfortunately, the same code doesn't work for hashchange events. here is my code:
$('.parent').on('click', 'a', function(e) {
e.preventDefault(); // this works perfectly fine
});
$(window).on('hashchange', function(e) {
e.preventDefault(); // doesn't work
});
According to the documentation , the hashchange
event is not cancellable, whereas a click
event is.
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.