力框架重装我有以下网页:window.location.hash =“”;在Chrome和Safari
<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 2012-08-08 14:49:24
@ColBeseder感谢您的提示。已经编辑我的问题:) – Fred 2012-08-13 15:02:55