有什麼不對的語法?這似乎並不爲我工作,即使如果我提醒哈希標籤和它與我的if語句匹配。如果(window.location.hash!= =「#搜尋」)
我的代碼:
if(window.location.hash) {
var thehash = window.location.hash;
if (thehash !== "#search"){
alert(thehash); // returns "#search"
thehash = thehash.replace(/#/g, '/');
window.location.replace("http://url.com/" + thehash + "/");
}
}
爲什麼會出現這種重定向仍然含有#搜尋
無法網址複製。您的代碼不會導致重定向URL時,片段是'#search'。在Chrome v23中測試過。 – lanzz
Futhermore,'thehash'沒有定義。也許這是由於複製的摘錄。 –
@DavidMüller感謝,現在修復它,對不起 –