Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Can the web page title be set to be dynamic?

I want to let some part to be updated in title, if any changes occur, an automatic update resulting in a bit of word addition to the title.

Example : the original one : "what is the title name"

Now after setting to automatic update when a event as an answer is posted - "what is the title name (1 answer)"

share|improve this question

5 Answers 5

up vote 4 down vote accepted

Your question needs to be clearer. Dynamic how? When getting information from a database? Or when a user interacts with a web page in such a way that a new page is not requested from the server?

Here's a generallized answer that hopefully helps to clear things up. The title of a page can be dynamic in two ways:

  • it is done serverside before being sent to the browser. This is how most dynamic pages generated. Whatever output is generated is what search engines will see. Any changes to the information in the database will be reflected in the page as soon as the new information is comitted in the databbase.

  • it is changed via JavaScript after the page is loaded in the browser. This change is not seen or indexed by search engines.

Update

Edited to reflect the clarification posted by the question asker

You can change the title of a page after it is loaded using JavaScript (the snippet in Shedokan's answer will work). Keep in mind that search engines only see the original output of a page when they request it. To use your example, if answers are added to the page after they crawled it you will need to wait until they crawl it again before those changes are reflected in the search engines indexes.

share|improve this answer
    
I think the question is plenty clear: "Can I change the title of the page while the user is on the page." Seems clear enough to me; I think you're overthinking it. Downvoted because @Shedokan gave a useful answer and this is not one. –  sequoia mcdowell Nov 2 '11 at 19:13
1  
They do not clarify if the change occurs client side or server side. Until they do the question is not clear. –  John Conde Nov 2 '11 at 19:15
    
If the question requires clarification, wouldn't a comment on the question be more appropriate? Submitting an "answer" that's primarily a request for clarification... that's not what *answer*s are for, unless I'm mistaken. –  sequoia mcdowell Nov 2 '11 at 19:19
    
If I only requested clarification a comment on the question would be more appropriate. But since I gave an answer that addressed the question from both a server side change and client side change I included it as part of my answer to help illustrate why the answer needs clarification. –  John Conde Nov 2 '11 at 19:21
1  
@sequoia, I think you're being overly critical. John Conde knows how the stackexchange works and has a vast expertise of 'the web'. He did the best he could given the question asked in it's original format, with updates after clarification.. what more could you want? –  Anonymous Nov 4 '11 at 7:28

If you want to change the page title without reloading the page then you'll have to do it in javascript:

document.title = 'Your new title';

You'll have to set the title even if you just want to change a part of it.

And if you want to update the title when a refresh occurs then you'll have to do it using your server side scripts.

share|improve this answer

Everything and anything can be dynamic on your page. You could even let one URL serve up a random page if you want.

If it's a good idea? I doubt. The question is what the search engines will make of it. Most likely it will not be beneficial SEO-wise.

share|improve this answer

In ASP.NET your dynamic pages inherit from System.Web.UI.Page which has a Title property, which you can set to whatever variable you want. So you may have some part of the title, which is shared by all the pages, stored in a file with other globals, and in the Page_Load method of a specific page you use it to "compute" the individual title.

share|improve this answer

If you want this done on the server side, you can set the title as a variable. Depending on your condition, you can then set the variable (title) to what you want. It's hard to tell exactly what you want to do, but a simple example of doing this--on the server side--using ColdFusion would be:

<cfparam name="title" default="No Title" type="string" />

<cfif isDefined("FORM.myName") AND FORM.myName NEQ "No Title">
  <cfset title = FORM.myName&"'s Page" />
</cfif>

<cfoutput>
<html>
  <head> 
    <title>#title#</title>
  </head>

<body>
  <form name="formName" action="thispage.cfm" method="post">
    <label for="myName">Name: </label>
    <input type="text" id="myName" name="myName" value="" />
    <input type="submit" />
  </form>
</body>
</html>  
</cfoutput> 

<cfparam name="title" default"No Title" type="string" /> sets the default title value when the page first loads. The default title will be No Title. When a user enters a name on the form, and submits the form back to itself, the title will change to the value they entered. For example, if the user enters Tom, then submits the form, the title will change from No Title to Tom's Page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.