我正在使用ajax更新框架中页面的位置.但是在设置哈希的位置时(特别是在Chrome和某些版本的IE(5.5)上,偶尔在IE7上),页面正在被重新加载.
以下html演示了这个问题.
主框架.... frame.html是
<html><head>
<frameset rows="*">
<frame src=sethash.html frameborder=0 scrolling=auto name=somebody>
</frameset>
</head></html>
Run Code Online (Sandbox Code Playgroud)
sethash.html页面是.
<html><head>
<script language=JavaScript>
var Count = 0;
function sethash()
{
top.document.location.hash = "hash" + Count;
Count++;
}
</script>
</head>
<body onload="alert('loaded')">
<h1>Hello</h1>
<input type='button' onClick='sethash()' value='Set Hash'>
</body>
</html>`
Run Code Online (Sandbox Code Playgroud)
在大多数浏览器中,加载frame.html会在加载页面时显示加载的警报.然后,当按下设置的哈希按钮时,URL将被更改,但加载的警报的哈希将不再显示.在Chrome和某些版本的IE上
Microsoft报告Internet Explorer 5.5 链接文本可能存在同样的问题
我不能使用microsoft建议的解决方案,即捕获事件而不是触发它,但只是滚动到视图,因为我使用set top.location.hash作为onLoad事件的一部分.