Forum Moderators: open
(1) - another text in the page title
(2) - another text in the page title
(3) - another text in the page title
(1)
/**
* Update the page title.
* @param {string} newValue The new title to set as the page title.
*/
function setPageTitle(newValue) {}
/**
* Given a message count, update the page title with the value.
* @param {string} msgCount The message count.
*/
function messageCountAsPageTitle(msgCount) {}
/**
* Send an AJAX request to get the message count from the server.
* @param {function} callback The function to call when the request completes.
* The callback should take 1 parameter, the string value of the message count.
*/
function getMessageCount(callback) {}
/**
* Update the page title.
* @param {string} newValue The new title to set as the page title.
*/
function setPageTitle(newValue) {
document.title = newValue;
}
/**
* Given a message count, update the page title with the value.
* @param {string} msgCount The message count.
*/
function messageCountAsPageTitle(msgCount) {
// TODO: determine where 'another text in the page title' should be defined
setPageTitle('(' + msgCount + ') - another text in the page title');
}
/**
* Send an AJAX request to get the message count from the server.
* @param {function} callback The function to call when the request completes.
* The callback should take 1 parameter, the string value of the message count.
*/
function getMessageCount(callback) {
var url = 'file1.php?' + (new Date()).getTime(), // prevent caching
xhr = getXHR();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
callback(xhr.responseText);
}
};
xhr.timeout = 20000; // Set the timeout to be less than the frequency we call this
xhr.open("GET", url, true);
xhr.send();
}
setInterval(function() {getMessageCount(messageCountAsPageTitle);}, 30000);