【发布时间】:2013-10-01 09:21:21
【问题描述】:
使用 Javascript 在域部分之后获取“任何”部分的最佳方法是什么:
http://www.domain.com/anything
http://www.domain.com/#anything
http://www.domain.com/any/thing
对于http://www.domain.com/#anything,我必须使用 window.location.hash。但是对于http://www.domain.com/anything,我将不得不使用 window.location.pathname。
我正在使用:
window.location.href.replace(window.location.origin, "").slice(1)
这个解决方案有什么注意事项吗?有没有更好的办法?
【问题讨论】:
标签: javascript url hash window.location