I have the following code:
$('ul.questions li a').click(function(event) {
$('.tab').hide();
$($(this).attr('href')).fadeIn('slow');
event.preventDefault();
window.location.hash = $(this).attr('href');
});
This simply fades a div in based on when you click but I want the page URL hash tag to change when you click so people can copy and bookmark it. At the moment this effectively reloads the page when the hash tag is change.
Is it possible to change the hash tag and not reload the page to prevent the jumping effect?
You could try catching the onload event. And stopping the propagation dependent on some flag.
Not tested, so can't say if it would work
The accepted answer didn't work for me as my page jumped slightly on click, messing up my scroll animation.
I decided to update the entire URL using
window.history.replaceState
rather than using thewindow.location.hash
method. Thus circumventing the hashChange event fired by the browser.You can simply assign it a new value as follows,
This works for me
Check here http://jsbin.com/edicu for a demo with almost identical code