Q:

How to correct #anchor scroll location in Firefox when ENTER is pressed in URL bar

I have a floating menu over the top of the page, so all anchor scroll positions are off by a given value. I am correcting this in Javascript by a very simple jQuery code:
if (window.location.hash !== '') {
    setTimeout(function() {
        var jumpPoint = $(window.location.hash).offset().top;
        var menuHeight = $('#menu').height();

        $(document).scrollTop(jumpPoint - menuHeight);
    }, 10);
}

This works well in both Firefox and Chrome, however there is one problem with Firefox which I don't know how to solve.
When the user clicks on a link or opens a new tab, Firefox runs JS and fixes the scrolling position by .scrollTop().
However when a user just clicks ENTER on an already open page, Firefox doesn't re-run JS, it just makes a quick anchor jump. That jump arrives in the wrong position, as it's not fixed by the JS code. Chrome doesn't display such behaviour, as it re-runs JS even when ENTER is pressed on an already open page.

A:

$(window).on('load hashchange', function(){
    var offset = $(window.location.hash).offset();
    if (offset) $(document).scrollTop(offset.top - $('#menu').height());
});

