Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System to handle hash tags for tab content? (!#)

I have four pages on the main part of the website I am working on, with tabs to switch between them. I want the switching between the 4 tabs to be a fading transition (using jQuery). That's all fine and dandy, but I also want SEO to think of each as a separate page. I also want to be able to link to a URL and for it to pull up the right content, even though it is technically the same page.

Facebook does this (facebook.com/#!/another-string-here), and you can switch between pictures and so on, so it kind of acts as a javascript querystring.

This allows switching immediately, the ability to link to it, and yet each acts as its own page.

Is there a recommended method for how to do this?


UPDATE the best I've found is SammyJS -- haven't implemented but it looks to be the best answer: http://sammyjs.org/

like image 859
Kerry Jones Avatar asked Nov 14 '22 06:11

Kerry Jones


1 Answers

Let's say you have a base page, called services, and that page has two tabs: design and development (just for simplification). So if your domain was example.com, your hash URL upon clicking on the "Design" tab would look something like http://example.com/services#!/design, and similar for development. I'm assuming you know how to do that.

To make search engines recognize the tabs, what you do is make a static version of each page. So you'd have one at http://example.com/services/design and one at http://example.com/services/development. The href attribute of each tab would actually point to these static pages, but you would attach an onclick handler to each tab to make it go to the hash version.

This way, JavaScript-enabled clients would get the Ajaxy version of your page with the hash tags and the fading effects, while clients without JavaScript enabled (including web crawlers) would see normal, static links, and everybody wins.


For the record, this is similar to what Facebook does. They go a step further and use HTML5's new history.pushState() function in browsers that support it, in order to remove the need for the hash tag entirely. (See this question for more info.)

like image 58
Sasha Chedygov Avatar answered Nov 17 '22 05:11

Sasha Chedygov