IE6 / 7后退/前进按钮不更改window.location.hash
我有一个使用哈希导航的ajax webapp(JSF 2.0)。
我已在此答案的帮助下使用了事件触发功能,并setInterval()
在较旧的浏览器(主要是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()
功能未检测到变化。
有人找到解决方案了吗?谢谢!
-
考虑使用jQuery Hashchange插件来避免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>
-
更改location.hash,然后按“后退”按钮-IE的行为与其他浏览器不同
2021-01-31 关注 1 浏览142 1答案
-
如何在不跳文档的情况下更新window.location.hash?
2021-02-02 关注 0 浏览84 1答案
-
开启-window.location.hash-更改了吗?
2021-02-02 关注 0 浏览73 1答案
-
开启-window.location.hash-更改了吗?
2021-01-31 关注 0 浏览117 1答案
-
iframe在更改了src之后,不出现后退或者前进按钮怎么解决?
2021-01-11 关注 0 浏览108 2答案
-
前进和后退按钮以控制ajax加载
2021-01-31 关注 0 浏览68 1答案
-
反应分页按钮前进和后退python
2021-01-29 关注 0 浏览83 1答案
-
IE6(IE7)上的JSON
2021-01-31 关注 0 浏览82 1答案
-
IE6 + IE7 CSS问题,溢出:隐藏;-职位:相对;连击
2021-02-02 关注 0 浏览91 1答案
-
用CSS分别定义IE6、7、8的width属性,使其在IE6下的值为10p...
2022-03-03 关注 0 浏览49 1答案