更新的location.hash我试图建立一个JS脚本,将改变页面的位置,要回去,直到一个特定的散列位置中找到:history.back()不会在Chrome /火狐
var StopAtThisHash ='#';
var CurrentHash = window.location.hash;
var continueLoop = true;
while ((window.history.length>0) && (continueLoop))
{
window.history.back();
var NowWeAreAtHash = window.location.hash; //this never changes in Chrome
//actually, always seems to: CurrentHash == NowWeAreAtHash;
if(NowWeAreAtHash == StopAtThisHash)
continueLoop= false;
}
奇怪的是,在Chrome和FF中,window.location.hash在back()之后没有改变。历史长度也没有像我期望的那样减少1。循环无限期运行,浏览器挂起。
在IE 9中,这似乎按预期运行。
任何解决方法?
也许看看这个http://stackoverflow.com/questions/2305069/can-you-use-hash-navigation-without-affecting-history,因为你可以使用'history.replaceState(undefined,undefined,“#hash_value “)'来替换散列值 – Hendry