homepage Welcome to WebmasterWorld Guest from
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()

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

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)

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)

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