Get the anchor of an URL in Javascript

[2009-06-17]

If you think about it, it does make sense. But it might not be the first thing to come up with when you need to solve the problem. But you can get the anchor of an url like this:

window.location.hash

So, to scroll to and open a hidden div in Prototype, try this

Event.observe(window, 'load', function() {
  if (window.location.hash) {
    try { $$(window.location.hash).first().show(); } catch(e) { }
  }
});
 

Comments

_

Want to leave a msg?

_

 

No comments yet...