Is there a way to bind a function to the change of the current URL of the page?

I want to use it when an id is added to the URL. Example:

http://ferhrosa.pfsistemas.com/#posts changend to...