【发布时间】:2012-08-05 15:36:43
【问题描述】:
我有以下页面:
<head>
<script type="text/javascript">
$(document).ready(function(){
var hash = window.location.hash;
var src = hash.substring(1); //remove #
window.location.hash = "";
if(src != ''){
frames['principal'].document.location.href = decodeURIComponent(src);
}
});
</script>
</head>
<frameset rows="18%,*" class="pagecontainer">
<frame name="top" noresize src="site/paginatop.htm" target="top" scrolling="no" frameborder="0"/>
<frameset cols="11%,*">
<frame name="lateral" noresize src="site/paginalateral.htm" target="lateral" frameborder="0"/>
<frame name="principal" id="principal" noresize src="site/paginahome.htm" target="principal" frameborder="0"/>
</frameset>
</frameset>
当我在散列中加载带有 URL 的页面时,散列被加载到框架内[主体]。
但是,当我清除哈希(window.location.hash = "";)时,Chrome 和 Safari 会重新加载页面,因此 frame[principal] 获取默认值(site/paginahome.htm)。
我已经发现了一个报告该行为的错误https://bugs.webkit.org/show_bug.cgi?id=24578
任何解决方法将不胜感激!
提前致谢。
已解决
我用 window.history.replaceState 找到了解决问题的方法:
$(document).ready(function(){
var src = getHash();
if(src != ''){
frames['principal'].document.location.href = decodeURIComponent(src);
var strBrowser = navigator.userAgent.toLowerCase();
if (strBrowser.indexOf('chrome') > 0 || strBrowser.indexOf('safari') > 0) {
if(history.pushState) {
window.history.replaceState(null, window.document.title, '#');
}
}
else {
window.location.hash = "";
}
}
setFavicon();
});
【问题讨论】:
-
试着把问题缩短到重点。
-
@ColBeseder 感谢您的提示。已经编辑了我的问题:)
标签: javascript html google-chrome safari frameset