0

Please dont ask why I would want to do this, I just want to know if it's possible to call a javascript function if and only if a specific fragment ID is present. Thanks :)

(Yes this links with my previous question, but it was too dissimilar to append on to it) if this is not possible, is there another way of calling a javascript function based on the URL.

Code Bundle
  • 282
  • 1
  • 2
  • 14

1 Answers1

2

Yes. Of course it is. You can get the fragment, check it's value and then call a function if it matches.

if (window.location.hash == "#myfragment") {
    myFunction();
}
Matt Burland
  • 44,552
  • 18
  • 99
  • 171
  • Explain how to do all this please, I'm only just starting out with Function ID's :) – Code Bundle Oct 30 '12 at 13:20
  • I'll accept this in 9 minutes when I can, thankyou so much :) – Code Bundle Oct 30 '12 at 13:21
  • Ahhh... Running this with the #about ID, trying to call that about(), the result of the about() function is not working, I've checked it works normally as theres another thing that calls about on that page when clicked. – Code Bundle Oct 30 '12 at 13:26