Edit in JSFiddle

<a href="#fun">This link points to #fun</a>
* {
    font-family: sans-serif;
    font-weight: bold;
}
function goBack() {
    location.hash = '#back';
}
function datHash() {
    if(location.hash === '#fun') {
        document.body.innerHTML =
            'location.hash === ' + location.hash
            + '<br /><br />'
            + '<button>Hey, a Back button!</button>';
        
        var elBack = document.querySelector('button');
        if(window.addEventListener) {
            elBack.addEventListener('click', goBack);
        } else {
            elBack.attachEvent('onclick', goBack);
        }
    } else {
        document.body.innerHTML =
            'That was fun.';
    }
}

if(window.addEventListener) {
    window.addEventListener('hashchange', datHash);
} else {
    window.attachEvent('onhashchange', datHash);
}