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

后端 未结 2 1531
轻奢々
轻奢々 2021-01-13 09:11

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 wil

相关标签:
2条回答
  • 2021-01-13 10:05

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

    document.title = "New title (1) new message";
    
    0 讨论(0)
  • 2021-01-13 10:09

    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 讨论(0)
提交回复
热议问题