Make a Browser Tab blink with Javascript

Vladimir Nikolic

Vladimir Nikolic

February 13th, 2023

If you're a user of WorkZone.io, you may have already noticed that you receive instant notifications in your browser whenever someone mentions you in a task or updates a task that you're a part of.

However, we understand that you might not always be actively looking at the WorkZone tab. To ensure you never miss a notification, we've created a simple JavaScript solution to make the tab blink until you open it.

This way, you'll always be aware of new notifications in WorkZone, even when you're working in a different tab.

blinkBrowser(message) {
        let oldTitle = document.title;
        let timeoutId;
        const blink = () => {
            document.title = document.title == message ? ' ' : message;
        };
        const clear = () => {
            clearInterval(timeoutId);
            document.title = oldTitle;
            window.onmousemove = null;
            timeoutId = null;
        };

        if (!timeoutId) {
            timeoutId = setInterval(blink, 1000);
            window.onmousemove = clear;
        }
    }