473,839 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I change the document title?

(This is a repost -- the original got tucked away into an old thread
because I used the same Subject name.)

I'm trying to change the document title to add an asterisk when the
document becomes "dirty", as seen on editor applications.

I use the code below. Venkman shows that everything looks as expected.
The last line is for the debugger, which indicates that the title is
changed, but it does not display.

var newtitlenode = document.create Element("title" );
var newtext = document.create TextNode("MyTit le"+(dirty?"*": ""));
newtitlenode.ap pendChild(newte xt);
var headnode = document.getEle mentsByTagName( "head").item(0) ;
var oldtitlenode = document.getEle mentsByTagName( "title").item(0 );
headnode.replac eChild(newtitle node,oldtitleno de);
headnode = document.getEle mentsByTagName( "head").item(0) ;

How can I get the changed title to display?

I'm running NN 7.1.

Jul 23 '05 #1
4 18484
"Richard Trahan" <rt*****@optonl ine.net> wrote in message
news:DV******** ************@ne ws4.srv.hcvlny. cv.net...
(This is a repost -- the original got tucked away into an old thread
because I used the same Subject name.)

I'm trying to change the document title to add an asterisk when the
document becomes "dirty", as seen on editor applications.

I use the code below. Venkman shows that everything looks as expected.
The last line is for the debugger, which indicates that the title is
changed, but it does not display.

var newtitlenode = document.create Element("title" );
var newtext = document.create TextNode("MyTit le"+(dirty?"*": ""));
newtitlenode.ap pendChild(newte xt);
var headnode = document.getEle mentsByTagName( "head").item(0) ;
var oldtitlenode = document.getEle mentsByTagName( "title").item(0 );
headnode.replac eChild(newtitle node,oldtitleno de);
headnode = document.getEle mentsByTagName( "head").item(0) ;

How can I get the changed title to display?

I'm running NN 7.1.


<html>
<head>
<title>title.ht m</title>
<script type="text/javascript">
function titled() {
document.title += '*';
}
</script>
</head>
<body>
<a href="javascrip t:titled()">*</a>
</body>
</html>
Jul 23 '05 #2
McKirahan wrote:

(snip)

Yes, of course! That works, thank you.

In the interest of higher education, what was wrong with my node method?

Jul 23 '05 #3
Richard Trahan wrote:
McKirahan wrote:
Yes, of course! That works, thank you.
In the interest of higher education, what was wrong with my node method?


It would seem your code works - insert the following
immediately after your replace call:

var x = document.getEle mentsByTagName( "title").item(0 );
alert('The ' + x.nodeName
+ ' now has value: '
+ x.firstChild.no deValue
+ '\nand document.title is: '
+ document.title) ;

In Firefox and IE the TITLE has been replaced. FF
reports document.title as the old one and IE makes
it empty (but doesn't change the title in the window
title bar).

I can only guess that "title" is created when loading
the page and isn't refreshed it if part of the <head>
changes. Maybe you can play with document.write or innerHTML.
Jul 23 '05 #4
Richard Trahan wrote:

[changing title of the document]
In the interest of higher education, what was wrong with my node method?


According to the DOM/HTML specification the HTMLTitleElemen t inherits
from HTMLElement, which itself inherits from the core Element interface,
which gives it appropriate DOM methods. Since HTML defines the content
of TITLE as PCDATA, the title should be able to have text nodes and
change their node values.

However, AFAICS, the specification does not state that the [normalized]
text nodes inside the title should be considered as the title's value:-)

While IE has therefore decided to not create a text node, Mozilla and
Opera have however made the decision to have a text node for the title
value; in this regard, since changing the node's value does nothing, it
could probably be considered as a "bug" in those browsers, but certainly
not in regards of the reference.

Apart from altering document.title, there's another standard way to
change the title, though probably less supported: change the text
property of the TITLE element.

<URL:http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-79243169>
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2512
by: Frank Lehmann | last post by:
Hi newsgroup, could someone please tell how to change the title of a Web Form window through VB.NET code? In VB 6 I would write Me.Caption="title", and what is it in VB.NET?? Thanks for your help
3
55020
by: Matt | last post by:
Is there a way to change the title bar of the JavaScript alert box?? If we do the following, it always show Internet Explorer in the title bar of the box. What if I want to have title "My Title" on the alert box? alert("Hello"); any ideas? thanks!!
9
2371
by: Ian Renfrew | last post by:
Essentially, I want to prevent the display of the Microsoft Internet Explorer or any other branding tag in the document title. One technique that I've used is to insert multiple spaces after the desired title to push the tag off of the screen. (i.e. <title>Document Title &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>) I want to write some javascript to perform the same operation. How would this be written using javascript?
4
13594
by: DerekM | last post by:
I have a database project that I created with several forms and reports. I would like to be able to declare a single title and be able to change the title on all the forms and reports by changing a single variable. I think this is possible, however I don't know Visual Basic very well. I created a module named DBcommon with the following statements in it: Option Compare Database Global Const DBname As String = "Title String"
2
1956
by: Nathan Sokalski | last post by:
I would like to change the <title></title> of a page from a user control. I have been unable to find any property in VB that allows me to do this. The only thing I have been able to find that might be related is when in Design view, there is a property called title under the DOCUMENT object in properties, which leads me to believe that there may be a way to access a DOCUMENT.title somewhere (although that may be only for...
6
1494
by: Tumurbaatar S. | last post by:
How to change a document's title programmatically, from the Page_Load() for example?
5
3513
by: Christian Ista | last post by:
Hello, I have a problem to change title page at runtime. In the page ASPX : <title runat="server" id="pageTitle"></title> In code behind : public partial class _Default : System.Web.UI.Page
3
3139
by: Adam Lipscombe | last post by:
Folks, I want to be able to get title of a document that is presented within an Iframe with the id "popupFrame". There may be more than 1 instance of the iframe in the page. This is my code: var elementCount = document.all("popupFrame").length;
3
18307
by: geevaa | last post by:
Hi All, Using javascript i am displaying an alert... Is there is a way to change the title of the alert box displayed through Javascript Here is my simple javascript code <script type = "text/javascript"> alert('Hi All !!!') </script>
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10592
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5871
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4067
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.