2012-06-19 3 views
0

function window.location.pathname을 통해 경로 이름을 변경하고 싶습니다. 나는이 소스 코드를 가지고있다.window.location.pathname Chrome 대 Mozilla

var hash = window.location.hash; 
window.location.pathname = hash; 

Mozilla에서 제대로 작동하지만 Chrome에서는 작동하지 않습니다. 크롬이이 주소를 써주세요.

/23 %! stranka = novinky & cisloStranky = 1 & rubrika = novinky & clanek = 783? stranka = kontakty #! stranka = novinky & cisloStranky = 1 & rubrika = novinky & clanek = 783

해시 값은 #!stranka=novinky&cisloStranky=1&rubrika=novinky&clanek=783

누군가의 아이디어가 있습니까?

감사합니다.

+1

가능한 복제를 사용하여 해시가 포함되지 않도록하려면 http://stackoverflow.com/questions/3643041/ setting-javascript-window-location – radimpe

답변

1

location.hash에는 #도 포함되어 있음을 이해해야합니다. location.hash의 나머지 부분은 사양별로 URL 인코딩되어 있지만 #은 아닙니다.

"spec마다"라고 말하면서 Firefox에는 location.hash 속성과 관련된 bug이 있습니다.

값이 포함 된 해시로 location.pathname을 변경하려면 #을 인코딩해야합니다.

예 :

var hash=location.hash.substring(1) 
location.pathname='%23'+hash 

당신이 단지의

var hash=location.hash.substring(1) 
location.pathname=hash 
관련 문제