tkachuko tkachuko - 5 months ago 16
Javascript Question

Javascript ignores # in url

I was trying to extract url after domain. According to this question it is possible by calling

window.location.pathname
, but in my url
http://domain:host/something#random=123
it drops everything after
#
inclusive. Is there anything better out there than splitting or regex?

In code:

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


returns
/something


Desired behavior:

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


should return
/something#random=123


Thanks in advance.

Answer

Try using location.hash which should return #random=123