Member
Account Settings
Share AgencyGenius
Know someone who might benefit from AgencyGenius? We'd love it if you shared our platform with your networking group!

Documentation
Tool
We've listed the code documentation below.
Tab Title Changer Script Overview
The Tab Title Changer is a lightweight JavaScript snippet that dynamically modifies the browser tab title when users navigate away from your webpage. It uses the Page Visibility API to detect tab switching and provides customizable timing, messages, and optional blinking effects to re-engage users who have switched to other tabs.
HTML Structure
The generated HTML structure is minimal and non-intrusive:
- Container <div> with unique ID like tab-title-changer-1
- Internal <style> block setting display: none on the container
- <script> tag containing the self-executing function
- No visible UI elements - purely behavioral enhancement
- Zero impact on page layout or visual design
- Comment markers for easy identification: <!-- Tab Title Changer -->
JavaScript Core Implementation
The script uses an immediately invoked function expression (IIFE) for encapsulation:
- (function() { ... })(); pattern prevents global scope pollution
- const originalTitle = document.title; captures the page's original title
- Message strings stored in constants: awayMessage and optionally alternateMessage
- Timer variables: tabChangeTimer and blinkInterval when delays are configured
- Boolean flag blinkState tracks current message in alternating mode
- All variables scoped within the IIFE closure
Page Visibility API Usage
The script leverages the Page Visibility API for reliable tab detection:
- Event listener: document.addEventListener('visibilitychange', function() {...})
- Tab state check: if (document.hidden) determines if page is not visible
- document.hidden
returns true
when:
- User switches to another browser tab
- Browser window is minimized
- Another window covers the browser
- User locks the screen or switches desktops
- More reliable than blur and focus events
- Works consistently across modern browsers
Title Change Timing
The script supports configurable delays before title changes:
- Immediate change when delay is 0 seconds
- Delayed change using setTimeout
when delay > 0:
- clearTimeout(tabChangeTimer) cancels pending changes
- tabChangeTimer = setTimeout(function() {...}, delay * 1000)
- Delay converted from seconds to milliseconds
- Timer cleared when user returns to prevent queued title changes
- Maximum configurable delay typically 10 seconds
Blinking Effect Implementation
Optional blinking creates attention-grabbing title animations:
- Activated when blink interval > 0 seconds
- Uses setInterval
for continuous toggling:
- blinkInterval = setInterval(function() {...}, interval * 1000)
- Interval cleared with clearInterval(blinkInterval)
- Two blinking modes:
- Single message mode: Alternates between awayMessage and originalTitle
- Dual message mode: Alternates between awayMessage and alternateMessage
- State tracking: blinkState = !blinkState toggles boolean
- Title update: document.title = blinkState ? message1 : message2
Message String Handling
The script safely handles user-provided message strings:
- Double quotes escaped in generated code: message.replace(/"/g, '\\"')
- Supports Unicode characters and emojis directly
- No HTML parsing - messages treated as plain text
- Maximum practical length limited by browser tab width
- Special characters like < , > , & displayed literally
- Line breaks and tabs normalized to spaces in tab titles
State Restoration
When users return to the tab, the original title is restored:
- Triggered when document.hidden becomes false
- Immediate restoration: document.title = originalTitle;
- All timers cleared to prevent pending changes:
- clearTimeout(tabChangeTimer) if delay was active
- clearInterval(blinkInterval) if blinking was active
- Clean state ensures no residual effects
- Original title preserved throughout page lifecycle
Browser Compatibility
The script works across modern browsers with graceful degradation:
- Page Visibility API support:
- Chrome 33+, Firefox 18+, Safari 7+, Edge all versions
- IE 10+ with msvisibilitychange (not used in this implementation)
- Mobile browser support:
- iOS Safari 7+
- Chrome for Android 33+
- Samsung Internet 2.0+
- Fallback behavior: Script silently fails in unsupported browsers
- No polyfills required - uses native APIs only
- ES5 syntax ensures compatibility without transpilation
Performance Characteristics
The script is optimized for minimal performance impact:
- Single event listener on document object
- No DOM manipulation beyond title updates
- Timer cleanup prevents memory leaks
- Negligible CPU usage - only active during tab switches
- No network requests or external dependencies
- Typical script size: ~1KB uncompressed
- No impact on page load time or rendering
Installation Methods
The script can be installed in various locations:
- Global <head>
section:
- Affects all pages on the website
- Ideal for site-wide engagement strategy
- Single point of maintenance
- Page-specific <head>
section:
- Targeted implementation for specific pages
- Different messages for different page types
- A/B testing possibilities
- Before closing </body>
tag:
- Ensures DOM is fully loaded
- No need for DOMContentLoaded checks
- Slightly delayed initialization
- Widget containers or page builders:
- Drag-and-drop implementation
- No direct code access required
- May require HTML widget support
Configuration Examples
Common configuration patterns and their effects:
- Immediate static message:
- Delay: 0 seconds
- Blink interval: 0 seconds
- Effect: Instant title change, no animation
- Delayed appearance:
- Delay: 2 seconds
- Blink interval: 0 seconds
- Effect: Title changes 2 seconds after tab switch
- Blinking single message:
- Delay: 0 seconds
- Blink interval: 1 second
- Effect: Alternates between message and original title
- Alternating dual messages:
- Delay: 1 second
- Blink interval: 1.5 seconds
- Alternate message enabled
- Effect: Waits 1 second, then alternates between two messages
Security Considerations
The script maintains security best practices:
- No execution of user input - messages are strings only
- No eval() or innerHTML usage
- Scoped execution prevents global variable conflicts
- No external resource loading or AJAX calls
- No access to sensitive browser APIs
- No data collection or analytics tracking
- CSP (Content Security Policy) compatible with script-src 'unsafe-inline'
Create Your Tab Title Effect
This message will appear in the browser tab when users switch away from your page.
Customize Your Effect
Delay before changing the tab title after user leaves (0 = immediate)
Set to 0 for static text or higher for blinking effect
This message will alternate with the main message when blinking is enabled
This shows what users will see in their browser tab when they switch away from your page.
Click the button below to simulate switching tabs.
Get Your Code
Copy and paste this code into your website to add the tab title effect:
Make this unique if using multiple tab title changers on your site
- Go to the page editor
- Open "SEO & Settings" for that page
- Add the script to that individual page's head section
Features of this effect:
✓ Customizable message when users leave your tab
✓ Configurable delay before message appears
✓ Optional blinking effect to grab attention
✓ Alternate message support for variety
✓ Lightweight and performant
✓ No external dependencies

How to edit code using AI →
Resource Details:
Tab Title Changer captures user attention by dynamically modifying the browser tab title when visitors navigate away from your webpage. When users switch tabs or minimize the browser, it displays customizable messages with optional delays, blinking effects, and alternating text patterns. Perfect for reducing abandonment rates, recovering lost visitors, or creating urgency with promotional messages and re-engagement prompts. Lightweight implementation using the Page Visibility API, with support for multiple timing configurations, dual message modes, and instant or delayed activation. Zero dependencies, fully self-contained, and easily customizable through an intuitive generator interface.

NO-ACCESS
Only for Desktop Users
This page is only available on desktop.
Please Log in on a desktop to gain access.