homepage Welcome to WebmasterWorld Guest from 54.225.1.70
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Calling Javascript function from Anchor Tags
Eg: http://www.example.com/index.html#funtion1 would call function1()
cosmoyoda




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

Greetings,
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.

Thanks,

 

Fotiman




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

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
}

cosmoyoda




msg:3754940
 8:04 pm on Sep 29, 2008 (gmt 0)

Fotiman. Thank you for your quick answer!

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved