我需要检测 URL 导航到 anchor 的某些事件:
<a name="latest-topics"></a>
http://someserver.com/index.html#latest-topics
然后我想使用类似 onfocus
的事件, onclick
等
<a onclick="doSomething()" onfocus="doSomething()" name="latest-topics"></a>
有哪些选项可以在导航到此类 anchor 的精确事件中检测导航到该 anchor ?
或者我需要一个带有 setInterval
的计时器吗?持续轮询对 location.hash
的更改每隔几毫秒?
最佳答案
你可以这样做:
if(window.location.hash) {
// do your check here.
}
关于javascript - 检测导航至 <a name ="latest-topics"></a>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12405092/