How to create the title alert effect like Facebook?

How to create flashing title effect like facebook? Means, when you are chatting with someone and a new message is received, a title starts to switch between the original title and a message informing user of the arrival of new message giving a flashing effect.

Explanation by AdrianoKF:

Notice the window title cycling between something like "New message from Foo Bar" and the regular one after receiving a new chat message.



(function () {

var original = document.title;
var timeout;

window.flashTitle = function (newMsg, howManyTimes) {
    function step() {
        document.title = (document.title == original) ? newMsg : original;

        if (--howManyTimes > 0) {
            timeout = setTimeout(step, 1000);

    howManyTimes = parseInt(howManyTimes);

    if (isNaN(howManyTimes)) {
        howManyTimes = 5;


window.cancelFlashTitle = function () {
    document.title = original;



flashTitle("New Message from Matt Lunn");

... or...

flashTitle("New Message from John Smith", 10); // toggles it 10 times.

Set an interval that switches the title every few seconds. Untested code:

function flashTitle(pageTitle, newMessageTitle)
    if (document.title == pageTitle)
        document.title = newMessageTitle;
        document.title = pageTitle;

setInterval("flashTitle('Facebook', 'New message from John Doe!')", 800);

setInterval("var x='',y='',z=document;z.title=z.title==x?y:x",900);

Need Your Help

HTML/Javascript: how to access JSON data loaded in a script tag with src set

javascript html json html5 script-tag

I have this JSON file I generate in the server I want to make accessible on the client as the page is viewable. Basically what I want to achieve is:

How to verify if a file exists in a batch file?

windows batch-file cmd

I have to create a .BAT file that does this: