The Dynamic Favicon Updater is a lightweight JavaScript class designed to enhance user engagement by dynamically updating the favicon based on specific events or conditions. This framework allows web applications to communicate important information through the browser tab itself, even when the user is not actively viewing the page.
- Change favicon dynamically based on events or conditions
- Support for different states (e.g., notifications, status indicators)
- Customizable icons to match branding and application needs
- Automatic restoration to the original favicon when no events are active
- Cross-tab communication to ensure consistency across multiple browser tabs
- Priority management for multiple active states
- Error handling and input validation
- Web Applications: Enhance user experience by displaying real-time notifications or status updates in the favicon.
- Messaging Platforms: Indicate unread messages or new notifications directly in the browser tab.
- Monitoring Tools: Show system or service status updates through favicon changes.
Include the favicon-updater.js script in your HTML file:
<script src="path/to/favicon-updater.js"></script>Create a new instance of FaviconUpdater with the default favicon URL and any pre-defined states.
const faviconUpdater = new FaviconUpdater({
defaultIcon: 'path/to/default/favicon.ico',
states: {
'notification': 'path/to/notification/favicon.ico',
'error': 'path/to/error/favicon.ico',
'success': 'path/to/success/favicon.ico'
}
});Change the favicon based on a specific event or condition.
faviconUpdater.setState('notification');Remove a specific state from the active states.
faviconUpdater.clearState('notification');Set a custom favicon directly.
faviconUpdater.setFavicon('path/to/custom/favicon.ico');Handle multiple states with priority (e.g., error state takes precedence over notification).
faviconUpdater.setState('notification');
faviconUpdater.setState('error');
faviconUpdater.clearState('error');Specify the priority of each state.
faviconUpdater.setPriority('error', 10);
faviconUpdater.setPriority('notification', 5);Remove all active states and restore the default favicon.
faviconUpdater.clearAllStates();Retrieve the current list of active states.
const activeStates = faviconUpdater.getActiveStates();Retrieve the URL of the currently displayed favicon.
const currentIcon = faviconUpdater.getCurrentIcon();The framework includes error handling and input validation. If an operation fails (e.g., due to an invalid URL or state), an error will be thrown with a descriptive message.
const faviconUpdater = new FaviconUpdater({
defaultIcon: 'path/to/default/favicon.ico',
states: {
'notification': 'path/to/notification/favicon.ico',
'error': 'path/to/error/favicon.ico',
'success': 'path/to/success/favicon.ico'
}
});
faviconUpdater.setState('notification');
setTimeout(() => faviconUpdater.clearState('notification'), 5000);Contributions to the Dynamic Favicon Updater are welcome! Here are some ways you can contribute:
- Report bugs or request features by opening an issue on the GitHub repository.
- Improve documentation and examples.
- Write code to address open issues or add new features.
To contribute code:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and add tests if applicable.
- Submit a pull request with a clear description of your changes.
Please ensure your code follows the existing style and passes all tests before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, support, or to report issues, please open an issue on the GitHub repository.