How to make page title, auto refresh every x seconds (using javascript/jquery/others)

I have a php file lets say file1.php, that printing a variable, its dynamic numbers output that already always increasing, like private message numbers that coming or others :


<?php
echo $variable
?>

i want to put that variable output, in another files page title, lets say file2.php or file3.html,
in the front of the another files page titles, and auto refresh every x seconds, maybe like this :

(1) - another text in the page title

after x seconds, get a private message

(2) - another text in the page title

after another x seconds, get another private message

(3) - another text in the page title

or its ok if just like this, only the variable, without the another text in the page title

(1)

please share your knowledge to make it, maybe using javascript, jquery or others

A server cannot send information to a client. What has to happen is for the client to ask for information from the server, which can be where the client can use Ajax to poll the server on a regular basis.

For example, you can update the title to show the time/date with:


window.setInterval(function () {
    var title = document.head.getElementsByTagName('title')[0];
    title.innerHTML = new Date();
}, 1000);

In a similar manner, perhaps every 60 seconds or so, you can perform an Ajax request of the server for private messages or other information.