Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Calling Javascript function from Anchor Tags

Eg: http://www.example.com/index.html#funtion1 would call function1()

6:09 pm on Sep 29, 2008 (gmt 0)

5+ Year Member

I tried searching the forum for an answer on this topic, but I did not find a specific answer. Therefore I decided to start this thread. Hope my question is simple (seems like it is): Is there any possible way to call a function on Javascript from simply changing the anchor (# at the end of the URL address)?

I see websites that use Tabs and automatically change to a different tab depending on the anchor tag specified. I want to know if you guys have any ideas how this might be possible using Javascript.


7:41 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

You could get the window.location.hash property and perform some action based on the value.

var h = window.location.hash;
if (h == "#foo") {
// do something
else if (h == "#bar") {
// do something else
8:04 pm on Sep 29, 2008 (gmt 0)

5+ Year Member

Fotiman. Thank you for your quick answer!

The solution is pretty simple, just how I'd expect it.


Featured Threads

Hot Threads This Week

Hot Threads This Month