I have a game website. I want to be able to change the page title to alert players when a new news item affects them. I routinely use refreshing AJAX calls to refresh stats etc. These AJAX calls refer to a seperate php file. I have tried everything I can think of, but the solution eludes me.
Here is the AJAX call (NO I am not interested in Jquery)
function createXMLHttpRequest() {
if (typeof XMLHttpRequest != 'undefined') {
return new XMLHttpRequest();
}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
return false;
}
function refresh_stats() {
var xmlHttp3 = createXMLHttpRequest();
params = '';
xmlHttp3.open("POST","ajax/statsajax.php", true);
xmlHttp3.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp3.onreadystatechange = function() {
if(xmlHttp3.readyState == 4 && xmlHttp3.status == 200) {
var brokenstring = xmlHttp3.responseText.split("-@[-");
if ( brokenstring[0] == 'stats' ) {
document.getElementById("statbox").innerHTML = brokenstring[1];
}
}
}
xmlHttp3.send(params);
statupdate=setTimeout("refresh_stats()", 60000);
}
Here is a snippet of the PHP code that I am working with
if ($timecheck1['id'] > $player['news']) {
echo("<i><font color=red> * News! *</font></i>");
?> <script type="text/javascript">document.title = "*News!* Immortalix";</script> <?php
} else {?> <script type="text/javascript">document.title = "Immortalix";</script> <?php }
I am assuming that it is not working because it is being called from a different document. Any suggestions would be most helpful.