1

I posted earlier and got a brilliant response to some jQuery woes I had.

I have the following tabbed navigation code: http://pastebin.com/gg4kgGKz

The tab works brilliantly, however I would like it so if a user visits: http://www.site.com/#tab2 that tab2 automatically opens and same for #tab1 and so on.

Is this possible, and if so how do I achieve this with my code?

Here be me fiddle: http://jsfiddle.net/MjENc/8/

Many thanks for any pointers.

Michael

michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190

1 Answers1

0

One way to do it would be to use php. For instance you would use the GET method to get the tab number: e.g. www.yoursite.com/?tab=2 would give you a value for the GET variable 'tab'. You can then use jQuery to read that variable and use the 'trigger' function to 'click' the appropriate tab so that appears open. If no GET variable is set then you just open the first tab by default.

To retrieve GET variables with jQuery see here.

Community
  • 1
  • 1
Stephen Harris
  • 1,148
  • 13
  • 21
  • That sounds perfect. Now, I just need to figure out how to do it :) $tabNo = $_GET['tab']; is fine but just then taking that into the Javascript. I'm a bit unsure of :) Any pointers would be great. – michaelmcgurk Sep 14 '11 at 10:42
  • 1
    I've posted a page that might help, but I've seen another (much simpler way), but I've not tested it: – Stephen Harris Sep 14 '11 at 10:47
  • Perfectium. Thanks for this, Stephen. Will take a look shortly. – michaelmcgurk Sep 14 '11 at 10:49
  • Hi Stephen. Sincere apologies for not replying sooner, I've still to try it out. I will do so shortly and report back. Sorry again just been very busy with offline issues. – michaelmcgurk Sep 20 '11 at 08:06