views:

1328

answers:

9

I have a webpage that implements a set of tabs each showing different content. The tab clicks do not refresh the page but hide/unhide contents at the client side. Now there is a requirement to change the page title according to the tab selected on the page ( for SEO reasons ). Is this possible? Can someone suggest a solution to dynamically alter the page title via javascript without re-loading the page? Thanks in advance.

+2  A: 

document.title = 'test'

Kev
I use top.document.title to reference to window itself (I have framesets...)
Dror
Ah, good call...
Kev
-1 useless for SEO. Spiders don't yet use javascript.
Adriano Varoli Piazza
+2  A: 

Use document.title.

See this page for a rudimentary tutorial as well.

lc
-1 useless for SEO. Spiders don't yet use javascript.
Adriano Varoli Piazza
+20  A: 

I can't see how changing the page title via Javascript will help SEO. Most (or all) search bots do not run Javascript and will only read the initially loaded title that is the mark-up.

If you want to help SEO, then you will need to change the page title in the back-end and serve different versions of the page.

Sarat
agreed - this won't help SEO at all, as the crawlers won't do anything with your JS
annakata
Maybe they just want one title but all the content on the SE, but then a more friendly organization of data once you're on the page?
Kev
well then they're very much going against the whole concept of SEO
annakata
+11  A: 

You can just do something like, document.title = "This is the new page title.";, but that would totally defeat the purpose of SEO. Most crawlers aren't going to support javascript in the first place, so they will take whatever is in the element as the page title.

If you want this to be compatible with most of the important crawlers, you're going to need to actually change the title tag itself, which would involve reloading the page (PHP, or the like). You're not going to be able to get around that, if you want to change the page title in a way that a crawler can see.

Alex Fort
+3  A: 

Is this going to work? I don't think the search engine spiders are going to run your Javascript and detect the title change.

jwmiller5
+7  A: 

Using the document.title is how you would accomplish it in JavaScript, but how is this supposed to assist with SEO? Bots don't generally execute javascript code as they traverse through pages.

TheTXI
+1  A: 

But in order to get the SEO befits

You need to do a page reload when the page changes so that the search engine's see the different titles etc.

So make sure the page reload works first then add document.title changes

Pbearne
+3  A: 

You'll have to re-serve the page with a new title in order for any crawlers to notice the change. Doing it via javascript will only benefit a human reader, crawlers are not going to execute that code.

Bryan Denny
+2  A: 

One way that comes to mind that may help with SEO and still have your tab pages as they are would be to use named anchors that correspond to each tab, as in:

http://www.example.com/mypage#tab1, http://www.example.com/mypage#tab2, etc.

You would need to have server side processing to parse the url and set the initial page title when the browser renders the page. I would also go ahead and make that tab the "active" one. Once the page is loaded and an actual user is switching tabs you would use javascript to change document.title as other users have stated.

Rich