gamesmstr Posted February 21, 2014 Share Posted February 21, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286359-dynamic-change-of-page-title-from-ajax-called-page/ Share on other sites More sharing options...
gristoi Posted February 21, 2014 Share Posted February 21, 2014 Firstly it is 2014 you should have no need to build raw ( and outdated ) ajax calls like this. Consider switching to a modern JQuery method for your ajax calls Quote Link to comment https://forums.phpfreaks.com/topic/286359-dynamic-change-of-page-title-from-ajax-called-page/#findComment-1469822 Share on other sites More sharing options...
gamesmstr Posted February 21, 2014 Author Share Posted February 21, 2014 Please See above. As I stated before, I am NOT interested in jQuery. The AJAX works fine and has for years. I'm not going to go recode my site after 6 years just to say I have jQuery. What I am adding is just a little perk and is more related to how to change the page title from inside an ajax called php file than the javascript itself. Quote Link to comment https://forums.phpfreaks.com/topic/286359-dynamic-change-of-page-title-from-ajax-called-page/#findComment-1469829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.