Skip to content

TutorialsAndroid/KAlert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Version License CDN Status

KAlert.js

✨ KAlert.js is a lightweight, modern, animated alert dialog library for JavaScript projects.

It now matches the same direction as:

KAlert.js provides beautiful alert, confirm, prompt, progress, image, and WebView iframe dialogs with a clean promise-based API.


πŸš€ KAlert.js Official Website

Live demos, WebView dialog examples, CDN setup, API documentation, and full usage guide.

Explore KAlert.js Website



🌐 https://tutorialsandroid.github.io/KAlert/

❀️ Support the Project

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.

Sponsor on GitHub

Thanks for your support! πŸš€


πŸš€ What is New in v2.0.1

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.

New features

  • 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, and rounded.
  • 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.

✨ Features

Dialog Types

  • βœ… 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

Styling Features

  • βœ… 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

Advanced Features

  • βœ… 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

πŸ“· Screenshots

Modern Success Dialog

KAlert Web Dialog Modern Success Dialog
Error Dialog

KAlert Web Dialog Error Dialog
Warning Dialog

KAlert Web Dialog Warning Dialog
Info Dialog

KAlert Web Dialog Info Dialog
Question Dialog

KAlert Web Dialog Question Dialog
Confirm Dialog

KAlert Web Dialog Confirm Dialog
Input/Prompt Dialog

KAlert Web Dialog Input Prompt Dialog
Progress Dialog

KAlert Web Dialog Progress Dialog
Image Dialog

KAlert Web Dialog Image Dialog
WebView Dialog

KAlert Web Dialog WebView Dialog


πŸ“¦ Installation

Recommended CDN version locking

<script src="https://cdn.jsdelivr.net/gh/TutorialsAndroid/KAlert@v2.0.1/kalertdialog.js"></script>

That is it. The library automatically loads the required CSS and Font Awesome icons.


Latest CDN version

<script src="https://cdn.jsdelivr.net/gh/TutorialsAndroid/KAlert@latest/kalertdialog.js"></script>

For production apps, version locking is recommended.


⚑ Quick Start

KAlert.success({
  title: "Success",
  message: "Saved successfully!",
  confirmText: "Done"
});

🎨 Dialog Types

Supported dialog types:

normal
success
error
warning
info
question
progress
input
image
webview

Example:

KAlert.show({
  title: "Information",
  message: "Here is some useful information.",
  type: "info"
});

βœ… Success Dialog

KAlert.success({
  title: "Success",
  message: "Your action was completed successfully.",
  confirmText: "OK"
});

❌ Error Dialog

KAlert.error({
  title: "Oops...",
  message: "Something went wrong. Please try again.",
  confirmText: "Try Again"
});

⚠️ Warning Dialog

KAlert.warning({
  title: "Are you sure?",
  message: "This action cannot be undone.",
  confirmText: "Confirm",
  cancelText: "Cancel"
});

❓ Confirm Dialog

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");
  }
});

⌨️ Prompt Dialog with Validation

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);
  }
});

πŸ”„ Progress Dialog

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);

πŸ–ΌοΈ Image Dialog

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"
});

🌐 WebView Dialog

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");
  }
});

⚠️ Important WebView Note

KAlert.js uses an iframe for WebView dialogs.

Some websites block iframe embedding using:

  • X-Frame-Options
  • Content-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 embedding

Example using a local page:

KAlert.webView({
  title: "Privacy Policy",
  url: "/privacy-policy.html",
  webViewHeight: 420
});

🌐 WebView Options

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);
  }
});

🎨 Style Presets

KAlert.show({
  title: "Modern Dialog",
  message: "This dialog uses the rounded style preset.",
  type: "info",
  style: "rounded"
});

Available styles:

classic
modern
minimal
rounded

🎨 Custom Appearance

KAlert.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
});

πŸŒ™ Dark Mode

KAlert.show({
  title: "Dark Mode",
  message: "This dialog uses dark mode styling.",
  type: "info",
  darkMode: true
});

πŸ”” Callback APIs

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");
  }
});

πŸ“Œ API Summary

Main methods

KAlert.show()
KAlert.success()
KAlert.error()
KAlert.warning()
KAlert.info()
KAlert.question()
KAlert.confirm()
KAlert.prompt()
KAlert.progress()
KAlert.image()
KAlert.webView()
KAlert.modal()

Main options

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: false

WebView options

url: "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 Ecosystem

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:


πŸ›  Full Example

<!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>

πŸ“‚ CDN Versioning

Stable version:

<script src="https://cdn.jsdelivr.net/gh/TutorialsAndroid/KAlert@v2.0.1/kalertdialog.js"></script>

Latest version:

<script src="https://cdn.jsdelivr.net/gh/TutorialsAndroid/KAlert@latest/kalertdialog.js"></script>

πŸ“œ License

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.

About

Lightweight, modern, animated alert dialog library for JavaScript with alert, confirm, prompt, progress, image and WebView iframe dialogs.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors