Can Javascript detect the manual appending of an anchor to the current location? -


I have loaded some arbitrary HTML pages in my browser. Then in the address bar, I attach "# anchor-name" and press enter.

Since I only added an anchor and did not call on a separate page, the browser does not make any other calls to the server. So there is no onload event, etc.

Still, can some JavaScript detect this action on this page? how? What is the event

I think the answer is "no". Please prove me wrong.

Thanks

Note: Please assume that the URL does not contain any query string. It ends with "/index.html" or "/ / .. .. / P>

related question: Does not it matter if there is actually an anchor-name on the anchor page named? P>

There is an event in IE8 that you are looking for.

For the rest However, using a "normal" technique is to set up a piece of code that regularly checks the hash, to see if the last time it was called, and If there is a work done, then it has to be changed. However, it provides a solution of onshashchange which does not trust setInterval , although it looks very tight to be used in a reliable way. Simply stick to setInterval for all browsers:

  var hash = window.location.hash; SetInterval (function () (if (hash! = Window.location .hash) {hash has changed (hash = is. ​​Window.location.hash;}}, 2000); // 2 second timer, should be ok  

it does not matter Dta that there is no element with the available hash.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -