Execute JavaScript function when trying to go to HTML binding

Regardless of whether I try to switch to index.html # ExistingAnchor or index.html # NotExistingAnchor or any other anchor that may or may not exist on page I would like the javascript function to be run.

<html>
<body>
    <a name="ExistingAnchor"></a>
</body>
</html>

What javascript code can I use to achieve it?

Perhaps the page is already loaded, so I’ll just visit the HTML bindings on one page from the address bar of the browser without reloading the page.

Also, having visited a number of bindings on the same page, when I use the browser's back and forward buttons, I would like some kind of JavaScript function to also be launched so that I can determine which anchor I am currently - could you also report this?

+3
source share
1 answer

In modern browsers you can implement the onHashChange event, on IE6 / 7 you will need to use some tricks using iFrames and window.setTimeout.

The jQuery history plugin will achieve what you want if you use jQuery, if you cannot learn and port it for your needs. http://tkyk.github.com/jquery-history-plugin/

+5
source

All Articles