开发者

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

开发者 https://www.devze.com 2023-04-05 08:14 出处:网络
Every time you receive a new 开发者_如何学Cemail, 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 s

Every time you receive a new 开发者_如何学Cemail, 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.


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

document.title = "New title (1) new message";


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
});
0

精彩评论

暂无评论...
验证码 换一张
取 消