jason310771 Posted April 15, 2011 Share Posted April 15, 2011 I am looking to use a similar method as facebook chat does, where it alternates between the original title text and 'friendsName has sent you a message!...' how can I do this ? Quote Link to comment https://forums.phpfreaks.com/topic/233827-alternate-the-between-original-and-new-title/ Share on other sites More sharing options...
analog Posted April 15, 2011 Share Posted April 15, 2011 Just changing document.title should change the title. To make it switch between two different titles over and over you could use setInterval. Something like: <html> <head> <title>Original</title> </head> <body> <script language="javascript"> var originalTitle = document.title; var newTitle = "You have a message"; function toggleTitle() { if(document.title == originalTitle) document.title = newTitle; else document.title = originalTitle; } var interval = setInterval("toggleTitle()", 1000); // clearInterval(interval); call this to stop it toggling the title </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/233827-alternate-the-between-original-and-new-title/#findComment-1202096 Share on other sites More sharing options...
jason310771 Posted April 15, 2011 Author Share Posted April 15, 2011 ok i see how this works, what i also would like to do it have the number of message a user has which are stored in mysql but i do not want them to keep refreshing the page every minute or so to find out. Quote Link to comment https://forums.phpfreaks.com/topic/233827-alternate-the-between-original-and-new-title/#findComment-1202108 Share on other sites More sharing options...
analog Posted April 15, 2011 Share Posted April 15, 2011 You could use AJAX to do that. Have it fetch the output of a PHP script that outputs how many messages a user has and then display that. Just have it on an interval of a few seconds and it will check without the user needing to refresh. Quote Link to comment https://forums.phpfreaks.com/topic/233827-alternate-the-between-original-and-new-title/#findComment-1202121 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.