2014-11-19 2 views
0

나는 표시된 URL과 역사 스택을 조작 할 수 history.pushState 매개 변수 가져 오기를 제거하려면 어떻게해야합니까?

history.pushState('id','myTitle','myURL'); 

을 사용하고 있습니다. 지금은

history.pushState('id','myTitle','#justSomeHashtag'); 

http://example.com?mySubLinkedStuff=hotSubLinkedStuff#justSomeHashtag 나는 또한 mySubLinkedStuff의 값을 덮어하지만, 얻을 수있을 수없는 것 생성 할 때

history.pushState('id','myTitle','?mySubLinkedStuff=hotSubLinkedStuff'); 

: 내가 지금처럼 GET 매개 변수를 밀어하고 어떤 점에서 그것의 전부입니다.

원하는 결과 :

http://example.com#justSomeHashtag 또는 http://example.com/#justSomeHashtag

분명히 내가 서버를 통해 전체 왕복을 만들고 싶어하지 않고 나는 또한 휴대용 프로젝트를 유지하기 위해 절대 경로 또는 URL을 사용하지 않도록합니다.

+0

'history.pushState ('id ','title ','http : //example.com/#h 애쉬 ')'그것은 작동하지 않습니다? – Kraylog

+0

프로젝트 이식성 때문에 절대 주소 지정을 사용하지 않기를 바랍니다. 하지만 당신은 맞습니다 - 절대 URL은 물론 작동합니다. 질문이 수정되었습니다. – Max

+0

''/ # hash ''는 어떻습니까? – Kraylog

답변

0

NimrodArgov가 올바르게 말한대로 : 전체 URL을 푸시하면 기존 get-parameter 문자열 덮어 쓰기가 작동합니다. 따라서 응용 프로그램의 이식성을 보장하기위한 내가 이런 짓을 (다양한 도메인에 사용 가능한 유지) :

history.statePush(document.location.origin + window.location.pathname + '#myHashValue'); 

작품 완벽하게 빠른.

0

GET 매개 변수없이 현재의 주소를 밀어 : 그 외에는

history.pushState("id", "myTitle", 
    location.protocol + "//" + location.host + 
    location.pathname + location.hash 
); 

을;

history.pushState("id", "myTitle", 
    location.protocol + "//" + location.host + 
    location.pathname + location.search + "#myHashHere" 
); 

쿼리 변화를 추진하기 위해 내가 할 수있는 :

history.pushState("id", "myTitle", 
    location.protocol + "//" + location.host + 
    location.pathname + "?my=query&over=here" + location.hash 
); 

※ 죄송합니다 내가 충분히 카르마이없는

내가 할 수있는 해시 변화를 밀어 Max’s answer에 대한 의견 :/

관련 문제