How to put notifications in Title? [duplicate]

2

Following the example of facebook

    
asked by anonymous 08.05.2018 / 16:31

2 answers

2

You can do this by using a function in javascript :

function changeTitle() {
    var titulo = document.title;
    var numero = 5; // Número de notificações a ser exibidas
    var novoTitulo = '(' + numero + ') ' + titulo;
    document.title = novoTitulo;
}

It depends on you to change the numero variable to get the amount of notifications your user has.

    
08.05.2018 / 16:39
1

In the case of facebook and many other sites that use this technique, the result is obtained through reactive frameworks, example React , Vue , etc ...

in the title tag has the following

<title>{{notificações}} Facebook</title>

If WebSocket detects a new notification, the "notifications" interpolation will update with the correct value, this concept is called Two way data binding

    
08.05.2018 / 16:48