Playful tab-title come back nudge when users switch away
Tiny “Come Back” Tab Title Nudge
Sometimes you want a tiny, playful nudge when someone switches away from your tab.
This snippet watches for blur / focus events and swaps the
page title to a fun “come back” style message while your tab is in the background.
When the visitor returns, it restores the original title automatically, so your
real title stays intact.
It’s a small way to add personality to your site without changing layout, loading extra libraries, or modifying your content. Everything happens at the document title level, and the behavior is easy to toggle or customize with a few lines of JavaScript.
Copy-paste snippet
Drop this block onto any page where you want the tab-title nudge to run. You can place it in a shared layout or inside an individual template for specific pages.
<style>
/* No CSS required – everything here is pure JavaScript.
You can still style your page normally as usual. */
</style>
<script>
// Tiny "come back" tab-title nudge
(function () {
// Store the original title once
var originalTitle = document.title;
var timeoutId = null;
// Message to show while the tab is in the background
var awayMessage = '👋 Still here when you are';
// Optional: cycle through a couple of messages while away
var messages = [
'👋 Still here when you are',
'✨ Your page is waiting…',
'🔧 VibeScriptz says hi'
];
var useCycling = true; // set to false to use only awayMessage
var cycleIndex = 0;
var cycleDelay = 2500; // ms between messages
function startAwayCycle() {
if (!useCycling) {
document.title = awayMessage;
return;
}
// Reset index and kick off the loop
cycleIndex = 0;
function tick() {
document.title = messages[cycleIndex];
cycleIndex = (cycleIndex + 1) % messages.length;
timeoutId = setTimeout(tick, cycleDelay);
}
tick();
}
function stopAwayCycle() {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
// Restore the original title
document.title = originalTitle;
}
// When the tab loses focus: start the "come back" titles
window.addEventListener('blur', function () {
startAwayCycle();
});
// When the tab gets focus again: stop and restore
window.addEventListener('focus', function () {
stopAwayCycle();
});
// Extra safety: if the page visibility API is available,
// use it as well so it works when people switch tabs without
// fully blurring the window (some browsers/platforms).
if (typeof document.hidden !== 'undefined') {
document.addEventListener('visibilitychange', function () {
if (document.hidden) {
startAwayCycle();
} else {
stopAwayCycle();
}
});
}
})();
</script>
How to use it
You can drop this snippet on any page where you want the playful behavior. The script:
- Remembers the current
document.titleas the “real” title. - Starts rotating attention-grabbing messages when the tab is unfocused or hidden.
- Restores the original title as soon as the visitor comes back.
- Works with the standard focus/blur events plus the page visibility API for better coverage.
- Doesn’t require any framework, bundler, or CSS changes.
If you use a global layout, you can include it once and enable the behavior for a whole section of your site. For more targeted use, paste it into the template for a single landing page or tool.
Customizing the messages
You can edit the messages in the messages array so they match your tone:
- Swap the emojis to fit your niche (
💻,📊,🎮, etc.). - Use just one message by setting
useCycling = false;. - Adjust
cycleDelay(in milliseconds) to control how often messages rotate. - Change
awayMessageto set a single, simple line you like.
Where this works well
Because it only touches the document.title and listens for focus/blur
style events, this pattern stays lightweight and predictable. It doesn’t create
overlays, modify layout, or open any extra windows. That makes it a good fit for:
- Blogs that want a small personality boost.
- Utilities and tools that users might leave open while switching tabs.
- Landing pages where you’d like to gently remind people there’s content waiting.
If at any time you decide you don’t want the behavior, you can either remove the snippet entirely or gate it behind a simple feature flag so it only runs on specific pages. It’s a purely front-end tweak, so there’s nothing to migrate in your backend or database.
Comments (0)
No comments yet — be the first.