Automatically display Tab contents on page load - jQuery Tabs
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
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.
精彩评论