How can I write the Javascript callback code that will be executed on any changes in the URL fragment identifier (anchor)?
For example from http://example.com#a to http://example.com#b
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Google Custom Search Engines use a timer to check the hash against a previous value, whilst the child iframe on a seperate domain updates the parent’s location hash to contain the size of the iframe document’s body. When the timer catches the change, the parent can resize the iframe to match that of the body so that scrollbars aren’t displayed.
Something like the following achieves the same:
Google Chrome 5, Safari 5, Opera 10.60, Firefox 3.6 and Internet Explorer 8 all support the
hashchangeevent:and putting it together:
jQuery also has a plugin that will check for the hashchange event and provide its own if necessary – http://benalman.com/projects/jquery-hashchange-plugin/.
EDIT: Updated browser support (again).