β¨ KAlert.js is a lightweight, modern, animated alert dialog library for JavaScript projects.
It now matches the same direction as:
- KAlertDialog for native Android Java
- KAlertFlutter for Flutter / Dart
- KAlert.js for web / JavaScript
KAlert.js provides beautiful alert, confirm, prompt, progress, image, and WebView iframe dialogs with a clean promise-based API.
Live demos, WebView dialog examples, CDN setup, API documentation, and full usage guide.
If you find KAlert.js useful, please support the project:
β Star this repository
π Report issues
π‘ Suggest new features
π Share it with other developers
Follow me on Instagram for more developer content:
πΈ https://instagram.com/coderx09
If this library helps you, please consider supporting my open-source work.
Thanks for your support! π
KAlert.js v2.0.1 is a major feature upgrade release.
This release brings KAlert.js closer to the Android and Flutter versions by adding a more professional API, modern UI styling, WebView iframe dialogs, progress dialogs, image dialogs, prompt validation, callbacks, dark mode support, and stronger customization.
- Added modern shortcut APIs.
- Added
KAlert.success(). - Added
KAlert.error(). - Added
KAlert.warning(). - Added
KAlert.info(). - Added
KAlert.question(). - Added
KAlert.progress(). - Added
KAlert.image(). - Added
KAlert.webView(). - Added advanced
KAlert.modal()base API. - Added WebView iframe dialog support.
- Added Terms and Privacy Policy dialog support.
- Added Help, FAQ, documentation and hosted page dialog support.
- Added progress/loading dialog support.
- Added image dialog support.
- Added big and circle image modes.
- Added prompt validation support.
- Added custom HTML support.
- Added close button support.
- Added dark mode option.
- Added style presets:
classic,modern,minimal, androunded. - Added title, message, and button font weight options.
- Added custom icon color, confirm button color, and cancel button color options.
- Added show, dismiss, confirm, cancel, input confirm, WebView load and WebView error callbacks.
- Improved accessibility with dialog role and keyboard handling.
- Improved overlay, animation, mobile responsiveness, and body scroll locking.
- β Normal dialog
- β Success dialog
- β Error dialog
- β Warning dialog
- β Info dialog
- β Question dialog
- β Confirm dialog
- β Prompt/input dialog
- β Progress/loading dialog
- β Image dialog
- β WebView iframe dialog
- β Custom HTML dialog
- β Modern UI
- β Smooth animations
- β Blur overlay background
- β Rounded dialog corners
- β Classic style preset
- β Modern style preset
- β Minimal style preset
- β Rounded style preset
- β Dark mode support
- β Custom dialog width
- β Custom icon colors
- β Custom confirm button color
- β Custom cancel button color
- β Title font weight support
- β Message font weight support
- β Button font weight support
- β Button all-caps control
- β Promise-based API
- β Input validation
- β Keyboard Enter support for prompt
- β Escape close support
- β Outside click close support
- β Close button support
- β WebView loading progress
- β WebView center loader
- β WebView sandbox support
- β WebView load callback
- β WebView error callback
- β Image error fallback
- β Custom HTML content
- β No build setup required
- β Works via CDN
Modern Success Dialog
|
Error Dialog
|
Warning Dialog
|
Info Dialog
|
Question Dialog
|
Confirm Dialog
|
Input/Prompt Dialog
|
Progress Dialog
|
Image Dialog
|
WebView Dialog
|
That is it. The library automatically loads the required CSS and Font Awesome icons.
For production apps, version locking is recommended.
KAlert.success({
title: "Success",
message: "Saved successfully!",
confirmText: "Done"
});Supported dialog types:
normal
success
error
warning
info
question
progress
input
image
webviewExample:
KAlert.show({
title: "Information",
message: "Here is some useful information.",
type: "info"
});KAlert.success({
title: "Success",
message: "Your action was completed successfully.",
confirmText: "OK"
});KAlert.error({
title: "Oops...",
message: "Something went wrong. Please try again.",
confirmText: "Try Again"
});KAlert.warning({
title: "Are you sure?",
message: "This action cannot be undone.",
confirmText: "Confirm",
cancelText: "Cancel"
});KAlert.confirm({
title: "Delete this file?",
message: "This action cannot be undone.",
confirmText: "Delete",
cancelText: "Cancel"
}).then((result) => {
if (result) {
console.log("User confirmed");
} else {
console.log("User cancelled");
}
});KAlert.prompt({
title: "Enter your name",
message: "Please enter at least 3 characters.",
placeholder: "Type here...",
validator: (value) => {
if (value.trim().length < 3) {
return "Name must be at least 3 characters";
}
return null;
}
}).then((value) => {
if (value) {
console.log("Name:", value);
}
});KAlert.progress({
title: "Processing",
message: "Please wait while we prepare your request."
});You can close it manually by using your own app flow or showing another dialog after async work.
KAlert.progress({
title: "Processing",
message: "Please wait..."
});
setTimeout(() => {
KAlert.success({
title: "Completed",
message: "Your request has been completed successfully."
});
}, 3000);KAlert.image({
title: "Image Preview",
message: "This image is loaded inside KAlert.js.",
imageUrl: "https://example.com/image.png",
imageType: "big",
confirmText: "Close"
});Circle image:
KAlert.image({
title: "Profile Image",
imageUrl: "https://example.com/avatar.png",
imageType: "circle"
});KAlert.js supports WebView-style iframe dialogs for showing hosted web pages inside a dialog.
This is useful for:
- Terms and Conditions
- Privacy Policy
- Refund Policy
- Help pages
- FAQ pages
- Documentation pages
- Hosted HTML content
KAlert.webView({
title: "Terms & Privacy Policy",
message: "Please read before continuing.",
url: "https://example.com/privacy-policy",
webViewHeight: 420,
confirmText: "I Agree",
cancelText: "Cancel"
}).then((accepted) => {
if (accepted) {
console.log("Accepted");
}
});KAlert.js uses an iframe for WebView dialogs.
Some websites block iframe embedding using:
X-Frame-OptionsContent-Security-Policy frame-ancestors
If a website blocks iframe embedding, the page may not display inside the dialog.
For best results, use:
Your own hosted Terms page
Your own Privacy Policy page
Same-origin page
A page that allows iframe embeddingExample using a local page:
KAlert.webView({
title: "Privacy Policy",
url: "/privacy-policy.html",
webViewHeight: 420
});KAlert.webView({
title: "Terms & Privacy Policy",
message: "Please read before continuing.",
url: "https://example.com/privacy-policy",
webViewHeight: 420,
webViewTitle: "Privacy Policy",
showHorizontalProgress: true,
showCenterLoader: true,
sandbox: "allow-same-origin allow-scripts allow-forms allow-popups",
allow: "clipboard-read; clipboard-write; fullscreen",
confirmText: "I Agree",
cancelText: "Cancel",
onWebViewLoad: (url, iframe) => {
console.log("Loaded:", url);
},
onWebViewError: (url, iframe) => {
console.log("Failed:", url);
}
});KAlert.show({
title: "Modern Dialog",
message: "This dialog uses the rounded style preset.",
type: "info",
style: "rounded"
});Available styles:
classic
modern
minimal
roundedKAlert.show({
title: "Custom Appearance",
message: "This dialog has custom colors and font weights.",
type: "success",
width: 420,
iconColor: "#10b981",
confirmButtonColor: "#10b981",
cancelButtonColor: "#e5e7eb",
titleFontWeight: 900,
messageFontWeight: 500,
buttonFontWeight: 900,
buttonAllCaps: false
});KAlert.show({
title: "Dark Mode",
message: "This dialog uses dark mode styling.",
type: "info",
darkMode: true
});KAlert.show({
title: "Callbacks",
message: "This dialog has lifecycle callbacks.",
type: "info",
showCancel: true,
onShow: () => {
console.log("Dialog shown");
},
onDismiss: (value) => {
console.log("Dialog dismissed", value);
},
onConfirm: () => {
console.log("Confirmed");
},
onCancel: () => {
console.log("Cancelled");
}
});KAlert.show()
KAlert.success()
KAlert.error()
KAlert.warning()
KAlert.info()
KAlert.question()
KAlert.confirm()
KAlert.prompt()
KAlert.progress()
KAlert.image()
KAlert.webView()
KAlert.modal()title: "Dialog title"
message: "Dialog message"
type: "success"
style: "modern"
confirmText: "OK"
cancelText: "Cancel"
showConfirm: true
showCancel: false
showCloseButton: false
closeOnOutside: true
closeOnEsc: true
darkMode: false
width: 380
iconColor: "#22c55e"
confirmButtonColor: "#22c55e"
cancelButtonColor: "#e5e7eb"
titleFontWeight: 800
messageFontWeight: 400
buttonFontWeight: 800
buttonAllCaps: falseurl: "https://example.com/privacy-policy"
webViewUrl: "https://example.com/privacy-policy"
webViewHeight: 420
webViewTitle: "Privacy Policy"
showHorizontalProgress: true
showCenterLoader: true
sandbox: "allow-same-origin allow-scripts allow-forms"
allow: "clipboard-read; clipboard-write; fullscreen"
onWebViewLoad: (url, iframe) => {}
onWebViewError: (url, iframe) => {}KAlert.js is part of the KAlert dialog ecosystem:
| Library | Platform | Package | WebView Support |
|---|---|---|---|
| KAlert.js | Web / JavaScript | jsDelivr CDN | iframe dialog |
| KAlertDialog | Native Android Java | Maven Central | Native WebView |
| KAlertFlutter | Flutter / Dart | pub.dev | webview_flutter |
Related libraries:
- KAlertDialog for Android Java: https://github.com/TutorialsAndroid/KAlertDialog
- KAlertFlutter for Flutter: https://github.com/TutorialsAndroid/KAlertFlutter
<!doctype html>
<html>
<head>
<title>KAlert.js Demo</title>
</head>
<body>
<button onclick="showDialog()">Show Dialog</button>
<script src="https://cdn.jsdelivr.net/gh/TutorialsAndroid/KAlert@v2.0.1/kalertdialog.js"></script>
<script>
function showDialog() {
KAlert.webView({
title: "Terms & Privacy Policy",
message: "Please read before continuing.",
url: "/privacy-policy.html",
webViewHeight: 420,
confirmText: "I Agree",
cancelText: "Cancel"
}).then((accepted) => {
if (accepted) {
console.log("Accepted");
}
});
}
</script>
</body>
</html>Stable version:
Latest version:
MIT License
Free for personal and commercial use.
Made with β€οΈ by TutorialsAndroid
If this library helps you, please β star the repository and share it with other developers.









