views:

42

answers:

2

I have four pages on the main part of the website I am working on, and 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, it kind of acts as a javascript querystring or.

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

Is there a recommended method to do this?

A: 

Well to have it both ways is impossible (facebook method and SEO), because the server doesn't get sent the hash tag, and most search engines (google etc.) don't run javascript.

Now if you simply want the fading effect, you can set it up so that if there is a hash tag in the url, for example #fade, jquery will set the opacity to 0, wait for load and fade in. To get the fade out you set event listeners on the links, e.preventDefault() or return false in that function, and fade out the opacity. Once it is done fading you would have javascript change to a new page location.href="site" with the hash #fade

Edit: example: http://fiddle.jshell.net/msm595/u5Eg2/3/show/light/

Alex Nolan
It's not impossible. You could allow both hash URLs and normal ones (e.g. example.com/somepage AND example.com/#!/somepage). That way JavaScript-enabled clients get the Ajaxy version with fading and all that, and crawlers and clients without JavaScript enabled will still be able to access the pages.
musicfreak
true, true. that could work
Alex Nolan
+1  A: 

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.)

musicfreak
Kudos for the link to that question, it had links for how Google is reading hash tags for ajax content and how to make it all work.
Kerry