AlertifyJS - Browser Dialogs & Notifications
raw JSON →AlertifyJS is a lightweight JavaScript framework designed for creating customizable and visually appealing browser dialogs (alerts, confirms, prompts) and unobtrusive notification messages. Currently stable at version 1.14.0, the package was last updated approximately two years ago, suggesting an inactive release cadence. It aims to replace native browser dialogs, which are often blocking and visually inconsistent, with a more modern and user-friendly experience. Key differentiators include its small footprint, out-of-the-box theme support (AlertifyJS, Semantic UI, Bootstrap), responsiveness across devices, and built-in internationalization (i18n) and Right-to-Left (RTL) layout support. Unlike full-fledged UI libraries, AlertifyJS focuses solely on dialogs and notifications, offering a simple API for common use cases.
Common errors
error Uncaught ReferenceError: alertify is not defined ↓
import alertify from 'alertifyjs';) or that the script tag for the library is included and loaded before any alertify calls in a global context. error Dialogs appear as unstyled, basic browser prompts/alerts. ↓
import 'alertifyjs/build/css/alertify.min.css'; and import 'alertifyjs/build/css/themes/default.min.css'; (or another theme) to your JavaScript entry point, or link them directly in your HTML <head> section. error TypeError: Cannot read properties of undefined (reading 'alert') ↓
import alertify from 'alertifyjs'; is used for ESM or const alertify = require('alertifyjs'); for CJS, ensuring the exported alertify object is correctly assigned and accessible. Warnings
breaking The license for AlertifyJS changed from MIT to GPLv3 starting with version 1.8.0. This is a significant change in licensing terms that affects how the software can be used, modified, and distributed, especially in commercial projects. ↓
breaking AlertifyJS is an 'extreme makeover' of the original `alertify.js` library by @fabien-d. This implies significant API changes and behavioral differences, meaning code written for `alertify.js` will likely not work directly with AlertifyJS without modification. ↓
gotcha If a callback is provided to a notification (e.g., `alertify.success('message', callback)`), clicking the notification message will not automatically close it. This differs from previous behavior in the original `alertify.js` and might lead to unexpected user experience if not accounted for. ↓
gotcha AlertifyJS supports the `prefers-reduced-motion` CSS media feature. If a user has enabled reduced motion in their operating system settings, all animation and transition effects within AlertifyJS will be automatically disabled to respect user preference. ↓
gotcha When using bundlers or module loaders, explicitly importing the necessary CSS files (core and theme) is crucial. Neglecting these imports will result in unstyled, basic browser dialogs and notifications, which do not align with the library's 'pretty dialogs' promise. ↓
Install
npm install alertifyjs yarn add alertifyjs pnpm add alertifyjs Imports
- alertify wrong
const alertify = require('alertifyjs');correctimport alertify from 'alertifyjs'; - CSS (Core) wrong
import 'alertifyjs/alertify.min.css';correctimport 'alertifyjs/build/css/alertify.min.css'; - CSS (Theme) wrong
import 'alertifyjs/themes/default.min.css';correctimport 'alertifyjs/build/css/themes/default.min.css';
Quickstart
import alertify from 'alertifyjs';
import 'alertifyjs/build/css/alertify.min.css';
import 'alertifyjs/build/css/themes/semantic.min.css'; // Or 'default.min.css', 'bootstrap.min.css'
// Basic Alert
alertify.alert('Hello World!', function(){ alertify.message('You clicked OK'); });
// Confirm Dialog
alertify.confirm('Confirm Action', 'Are you sure you want to proceed?',
function(){
alertify.success('You clicked OK');
},
function(){
alertify.error('You clicked Cancel');
}
);
// Prompt Dialog
alertify.prompt('Prompt Example', 'Please enter your name:', 'Anonymous',
function(evt, value){
alertify.success(`Hello ${value}!`);
},
function(){
alertify.error('You clicked Cancel');
}
);
// Notification Message
alertify.success('Success message here!');
alertify.error('Error message here!');
alertify.warning('Warning message here!');
alertify.message('Normal message here.');
console.log('AlertifyJS initialized and examples run.');