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]
<?php
echo $variable
?>
[/PHP]

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

document.title = "(1) GET ME PAID BITCH";
document.title = "(2) WEALTHS, FAMES, LUXURIES";
document.title = "(3) DOLLA DOLLA BILLS YALLS ";
document.title = "(4) BUY MY KENNY POWERS MEMORABILIA";
document.title = "(4) OR YOUR FUCKING OUT ";

document.title = "(1) TITLE";
document.title = "(2) ???";
document.title = "(3) PROFIT!";

   <script typee="text/javascript"> 
function titlebar(val)
{
	var msg  = "I am the one percent";
	var speed = 500;
	var pos = val;
 
	var msg1  = "    I sort glass its my job!!!";
	var msg2  = "    !!I know it by heart!!";
 
	if(pos == 0){
		masg = msg1;
		pos = 1;
	}
	else if(pos == 1){
		masg = msg2;
		pos = 0;
	}
 
	document.title = masg;
	timer = window.setTimeout("titlebar("+pos+")",speed);
}
 
titlebar(0);
</script>

   <script typee="text/javascript"> 
function titlebar(val)
{
	var msg  = "I am the one percent";
	var speed = 500;
	var pos = val;
 
	var msg1  = "    I sort glass its my job!!!";
	var msg2  = "    !!I know it by heart!!";
 
	if(pos == 0){
		masg = msg1;
		pos = 1;
	}
	else if(pos == 1){
		masg = msg2;
		pos = 0;
	}
 
	document.title = masg;
	timer = window.setTimeout("titlebar("+pos+")",speed);
}
 
titlebar(0);
</script>