0

I need to detect some event in which an URL navigates to an anchor:

<a name="latest-topics"></a>

http://someserver.com/index.html#latest-topics

And then I would like to use some event of the kind of onfocus, onclick, etc.

<a onclick="doSomething()" onfocus="doSomething()" name="latest-topics"></a>

What options are there to detect navigating to such anchor in the precise event of navigating to it?

Or would I need a timer with setInterval to continuously poll changes to location.hash every few milliseconds?

alt.126
  • 1,097
  • 1
  • 9
  • 22

1 Answers1

2

you can do this onload:

if(window.location.hash) {
 // do your check here.
}
Zack Marrapese
  • 12,072
  • 9
  • 51
  • 69