It may be a problem in PHP if you're not using the sum by JavaScript, but if it's on the front end then I'll explain what might be going on.
Assuming the code is actually this ( since what was posted does not make sense ):
<?php
echo 'document.title = "(' . $total_notifi . ') " + title;';
Then the updates now occur in the front-end by increment, so the code here can update the title by accessing the title already coming from php (backend)
Something like:
document.title += "(1)";
If the problem really is in javascript, then you should convert to int
using parseInt
for example and also do the necessary treatments, something like:
-
javascript:
//Valor que virá do ajax ou js que você fez e será somado
function atualiza(soma) {
var re = /^\(\d+\)/g;
var res = document.title.match(re);
//Pega o total no titulo
var atual = res && res[0] ? parseInt(res[0].replace(/\(|\)/g, "")) : 0;
//Remove o total e os '()' do titulo
var titulo = document.title.replace(re, "");
document.title = "(" + (atual + parseInt(soma)) + ") " + titulo;
}
setInterval(atualiza, 1000, 1); //Adiciona +1 (terceiro parâmetro)
-
html:
<title>(<?php echo $total; ?>) Home</title>
However as I already mentioned, the problem may be in php.
Note that (<?php echo $total; ?>)
is optional and if the update comes from ajax, as it is on Facebook or Twitter, that is, the script here can adapt to any title without having to be in a variable, examples of pages that the (1)
will be added:
home:
<title>Home</title>
Blog:
<title>Blog</title>
And Ajax (Jquery example) would look something like:
$.ajax("update.php").done(function(data) {
atualiza(data);
});
After running it on any page the result will be something like:
home:
(2) Home
Blog:
(2) Blog
That is this way that made the title is updated regardless of the original content.