jQuery Javascript scrollTop not working as expected on Chrome to restore scrollbar position
<p>I'm using the following jQuery Javascript to save the scrollbar position before the unload event and reapply it again:</p>

<pre><code>$(document).ready(function () {
    document.documentElement.scrollTop = $.cookie("scroll") || 0;
});

window.onbeforeunload = function () {
    $.cookie("scroll", document.documentElement.scrollTop, { expires: 7 });
}
</code></pre>

<p>Basically I have a series of links that refresh the page and I would like the browser to restore the scrollbar position. Note I cannot use AJAX in this instance. It works a treat in Firefox. In Chrome and Safari however it only works when the browser window is refreshed, and not when the link is clicked to refresh the page. It's as if clicking the link isn't being recognised as onbeforeunload.</p>

<p>I have tried to modify the code to set the scroll cookie using a click event as follows with no luck:</p>

<pre><code>$(document).ready(function () {
    document.documentElement.scrollTop = $.cookie("scroll") || 0;
});

$('a.lockscrollbar').click(function() {
    $.cookie("scroll", document.documentElement.scrollTop, { expires: 7 });
}
</code></pre>

<p>FYI I'm using jQuery 1.4.2 with the jQuery cookie plugin.</p>

<p>Any ideas?</p>
