2012-08-08 57 views
2

力框架重裝我有以下網頁: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(); 
}); 
+1

嘗試縮短問題的重點。 – ColBeseder 2012-08-08 14:49:24

+0

@ColBeseder感謝您的提示。已經編輯我的問題:) – Fred 2012-08-13 15:02:55

回答

0

在Chrome中,window.location.hash = ""不重新加載頁面。它只是將它滾動到頂部。

但也許使用POST會比散列更好地解決您的問題。

+0

你是半對的!我使用添加和刪除哈希的按鈕對Chrome進行了簡單測試,並且不會重新加載。這讓我對自己的問題更加絕望,並讓我找到原因!在框架上,它重新加載! [鏈接](https://bugs.webkit.org/show_bug.cgi?id=24578) – Fred 2012-08-13 14:44:06