How to place notifications in Title?

Asked

Viewed 79 times

2

Following the example of facebook

inserir a descrição da imagem aqui

  • Suggestion to avoid something like "(5) (4) (3) (2) (1) my title" when the expected should be "(5) my title" and for the use of ajax: https://answall.com/a/108449/3635

2 answers

2

You can do this using a function on 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;
}

Then it depends on you changing the variable numeroto get the amount of notifications your user has.

  • Thank you all, I’ve got it! :)

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....

on the tag title has the following

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

If Websocket detects a new notification, the "notifications" interpolation will update to the correct value, this concept is called Two way data Binding

Browser other questions tagged

You are not signed in. Login or sign up in order to post.