Website Scripts And Cloud Tutorials

How to change web page title using javascript

Byadmin

Sep 15, 2008

Last updated on May 12th, 2022 at 12:23 pm

Click to rate this tutorial!
[Total: 6 Average: 2.3]

The below script can be used to dynamically change title on the browser. There is a delay variable in the script you can modify it according to your convenience. By changing this value you can even Animate the web page title to an extend 🙂

In this tutorial we are updating document.title using Javascript.

<script type="text/javascript">
var message = new Array ();
var delay = 5000; // Sets the delay between switching messages
var currMessage = 1;
message[1] = "I am First";
message[2] = "I am Second";
message[3] = "I am Third";
 
function timer() {
document.title = (message[currMessage++]);
setTimeout("timer()",delay);
currMessage = ((currMessage >= message.length) ? 1 : currMessage);
}
timer();
</script>

If you would like to add more messages, add more values in the message array like below

message[1] = "I am First";
message[2] = "I am Second";
message[3] = "I am Third";
message[4]= "New Message";

Demo
Just add the above script on your webpage and see your title bar getting changed dynamically 🙂

Click to rate this tutorial!
[Total: 6 Average: 2.3]
13 thoughts on “How to change web page title using javascript”

Leave a Reply

Your email address will not be published.