Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update the title of the tab in the same way GMail/Facebook does?

Tags:

javascript

Every time you receive a new email, or something happens on your Facebook profile, your browser tab's name changes. For example, on gmail, if you receive a new mail, it will change to something like GMail (1). How can I get the same effect in my application? I think it's a Javascript thing, but I'm not sure.

like image 616
Geo Avatar asked Sep 17 '11 15:09

Geo


2 Answers

This should be as simple as modifying the document.title property with JavaScript:

document.title = "New title (1) new message";
like image 181
Michael Berkowski Avatar answered Nov 03 '22 00:11

Michael Berkowski


can be done using jQuery (Javascript library)

This sample will change title of page 2 seconds after document fully loads

function changeTitle(new_value){
    $("title").val(new_value);  //this line changes value of <title> element
    //pure javascript:  document.title = new_value;
}

$(document).ready(function(){
    setTimeout('changeTitle("New Title")',2000); //calls function changeTitle() after 2secs
});
like image 31
Marek Sebera Avatar answered Nov 03 '22 01:11

Marek Sebera