PDA

View Full Version : How to change text content of Title tag using DOM?



prost
September 5th, 2007, 01:47 AM
Hi!
I have a title tag:
<TITLE>Title - Old</TITLE>
I want to change it to:
<TITLE>Title - New</TITLE>

I tried the following:
<BODY>
<SCRIPT>
var DocTitle = document.getElementsByTagName("title")[0];
alert(DocTitle.nodeValue);
</SCRIPT>
</BODY>

The alert box gives a message "null"(IE). Hence, am not able to access the title tag text node and hence am not able to change the contents! Any suggesstions???

lab9design
September 5th, 2007, 10:32 AM
Have you seen this http://www.thescripts.com/forum/thread148055.html ?

AgentFitz
September 9th, 2007, 10:50 PM
or you could just go with:

document.title = "New Title";





<html>
<head>
<title>Old Title</title>
</head>


<body>

Hello, I'm the body.

<script type="text/javascript">
document.title = "new Title";
</script>
</body>
</html>