A quick dirty hack, but this is what you can rely on:
var curScroll = prevScroll = $(window).scrollTop()
$(window).bind('scroll', function() {
prevScroll = curScroll
curScroll = $(this).scrollTop()
}).bind('hashchange', function() {
$(this).scrollTop(prevScroll)
})
I used jQuery here to make it work in different browsers and maintain the integrity of the onhashchange page and onscroll handlers. One of the problems I noticed is that if you click on the same hashtag twice, it will scroll anyway.
UPD. I just found a better solution:
$('a').live('click', function() {
if (this.href.split('#')[0] == location.href.split('#')[0]) {
var scrollTop = $(window).scrollTop()
setTimeout(function() {
$(window).scrollTop(scrollTop)
}, 0)
}
})
source
share