力框架重裝我有以下網頁: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