Is there a function that can be called to prevent the browser from recording a back history entry when changing the hash value?
I am writing a simpl
You can use replaceState().
Before you change the hash you save the history, then you change your hash, finally you replace the history with the one you saved.
Alternatively you can use popState Event.
window.location.replace
will let you set the url without adding it to the browser history.
var baseUrl = window.location.href.split('#')[0];
window.location.replace( baseUrl + '#' + imageID );
documentation