Retaining scroll position per page (using localStorage)

For any site with longish pages and/or a complicated UI flow, losing your scroll position when moving back and forward in the browser's view stack can be a pain.

Fortunately, using jQuery and localStorage, retaining the user's vertical scroll for individual pages is a breeze:

var utils = {  
    scrollIntoPos: function () {
        $(window).unload(function () {
            utils.setScreenPos(window.location.href);
        });
        utils.getScreenPos(window.location.href);
    },

    getScreenPos: function (url) {
        if (localStorage.scrollPosition + url) {
            $("body").scrollTop(localStorage.getItem("scrollPosition" + url));
        }
    },

    setScreenPos: function (url) {
        var scrollPosition = $("body").scrollTop();
        localStorage.setItem("scrollPosition" + url, scrollPosition);
    }
};

//Include this globally
$(function() {
    utils.scrollIntoPos();
});

A real quick-and-easy one - hopefully this helps someone.