winow.onhashchange

名前から察しの通りlocation.hashが変更になったタイミングで動作する関数。初期値はnull。

alert(window.onhashchange); // null

sample.html

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" > 
    <script type="text/javascript">
    window.onhashchange = function(){
        alert(location.hash);
    };
    </script>
</head>
<body>

    <a href="sample.html#foo">foo</a>
    <a href="sample.html#bar">bar</a>

</body>
</html>