Is it possible to remove the hash from window.location
without causing the page to jump-scroll to the top? I need to be able to modify the hash without causing any jumps.
I have this:
$('<a href="#123">').text('link').click(function(e) {
e.preventDefault();
window.location.hash = this.hash;
}).appendTo('body');
$('<a href="#">').text('unlink').click(function(e) {
e.preventDefault();
window.location.hash = '';
}).appendTo('body');
See live example here: http://jsbin.com/asobi
When the user clicks 'link' the hash tag is modified without any page jumps, so that's working fine.
But when the user clicks 'unlink' the has tag is removed and the page scroll-jumps to the top. I need to remove the hash without this side-effect.