Javascript IE6/7后退/前进按钮don';t更改window.location.hash

Javascript IE6/7后退/前进按钮don';t更改window.location.hash,javascript,ajax,jsf-2,Javascript,Ajax,Jsf 2,我有一个ajax webapp(JSF2.0),它使用散列进行导航 我在和的帮助下使用了事件触发来检查旧浏览器(主要是IE6+7)中的值更改 执行此操作的Javascript代码: window.onload = window.onhashchange = function() { lastHash = window.location.hash; // To save a refresh on browsers that don't need it. var fragment =

我有一个ajax webapp(JSF2.0),它使用散列进行导航

我在和的帮助下使用了事件触发来检查旧浏览器(主要是IE6+7)中的值更改

执行此操作的Javascript代码:

window.onload = window.onhashchange = function() {
    lastHash = window.location.hash; // To save a refresh on browsers that don't need it.
    var fragment = document.getElementById('fragment');
    fragment.value = window.location.hash;
    fragment.onchange();
}

// Old Browsers That don't support onhashchange...
var lastHash = window.location.hash;
function checkFragment() {
    if (window.location.hash != lastHash) {
        lastHash = window.location.hash;
        var fragment = document.getElementById('fragment');
        fragment.value = window.location.hash;
        fragment.onchange();
    }
}
这很有效。也就是说,当我更改哈希值时,AJAX应用程序会收到通知并进行更新。 IE 6/7就是一个不起作用的例子。当我按下后退/前进按钮时,我可以看到url栏用正确的哈希值更新,但是
windows.location.hash
似乎没有变化,因此我的
SetEvent()
函数没有检测到变化

有人找到了解决办法吗? 谢谢

考虑使用以避免IE6/7兼容性问题。你可以找到。它可以根据您的情况进行如下更改

<script src="jquery.js"></script>
<script src="jquery-hashchange.js"></script>
<script>
    $(function(){
        $(window).hashchange(function(){
            $('#fragment').val(location.hash).change();
        });

        $(window).hashchange();
    });
</script>

$(函数(){
$(窗口).hashchange(函数(){
$('#fragment').val(location.hash.change();
});
$(window.hashchange();
});

嗯。。。在我看来像javascript,而不是java