Tuesday 28 September 2010

Create "Flashing" Page Title

If you wish to create a flashing page title (like the one used on Facebook Chat when you receive a new message) you can do so, by using some simple javascript.

To do this, you need to create a function which displays the alternative title, and a function which displays the original title. This gives the illusion that the alternative title is actually flashing on the page.

Each of these functions will first change the title of the page, and then set a timer to call the other function in x seconds.

var Original_Title
function FlashTitle()
{
Original_Title = document.title;
SetAlternateTitle();
}

function SetAlternateTitle()
{
document.title = "alternate title text!";
setTimeout("SetOriginalTitle();", 1000);
}
function SetOriginalTitle()
{
document.title = Original_Title;
setTimeout("SetAlternateTitle()", 1000);
}


Actioning FlashTitle()will cause your page title to change from its standard text to "alternate title text!" and then flash back, alternating every second.

No comments:

Post a Comment