2016-06-19 4 views
1

도메인을 따라 URL을 추출하려고했습니다. 이 question에 따르면 window.location.pathname을 호출하여 가능하지만 내 URL에 http://domain:host/something#random=123# 이후의 모든 것을 삭제합니다. 분할 또는 정규식보다 더 좋은 점이 있습니까? 코드에서Javascript는 URL에서 #을 무시합니다.

:

window.location.pathname("http://domain:host/something#random=123") 

반환 /something

원하는 동작 :

window.location.unknownMethodToMe("http://domain:host/something#random=123") 

사전에 /something#random=123

감사를 반환해야합니다.

+2

https://developer.mozilla.org/en-US/docs/Web/API/Location#Examples – epascarello

답변

3

내가 쓸 필요가 원하는 것을 달성하기 위해 그래서 #random=123

+0

를 반환해야 location.hash를 사용해보십시오 something : window.location.pathname (url) + window.location.hash? – tkachuko

+0

'window.location.pathname' 이'/ something'을 반환하면'location.hash'를 사용하여'# random = 123'을 검색 할 수 있습니다. – guest271314

관련 문제