2012-08-08 86 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