: Can the webpage title be changed after site has been loaded. 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
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)"
More posts by @Frith620
5 Comments
Sorted by latest first Latest Oldest Best
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.
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.
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.
Edit after "positive" feedback from @Shedokan , who reads the quastion a little different (as in changing the title dynamically, without any active refresh from the client side).
There are a few techniques to do so after the page has loaded, the latest (but not yet very reliable) way is using websockets. A more traditional (and currently more reliable) way is using long polling. There are several other "Push technologies" as well. There are libraries out there that will try websockets and automatically fallback to long polling if websockets is not working. I personally have used SignalR (using the .Net framework) which works very well. Note that if the info is important or requires immediate action, you should consider using notifications in addition, since the above mentioned techniques will usually only work while the browser is visible (at least on mobile devices like iPads).
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.
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.