FLASH SALE Get 20% OFF everything using the coupon code: FLASH20 View WordPress Plugins →

Tiny confirmation modal dialog in Vanilla JavaScript

on in JavaScript DOM
Last modified on

Thin UI Modal Dialog using Vanilla JavaScript
Thin UI Modal Dialog using Vanilla JavaScript

A new addition to my Thin UI library, a much-needed modal dialog (popup dialog), this script is tiny, and it works with anything you can throw at it. It’s written in Vanilla JavaScript with no dependencies.

One of my ongoing project needed several confirmations on several pages. As these actions might be delayed, I required something to work asynchronously. This script adds a custom Confirm popup dialog with Promise support to your website application.

The modal returns a Promise with the selected option: true if the user accepted, false if the user clicked cancel, and null if the user closed the modal window.

The modal constructor takes four parameters: the title, the content, and the button labels (“Accept” or “Cancel”).

See the example on the Thin UI page or a live Codepen below:

See the Pen RJS (alpha) by Ciprian (@ciprian) on CodePen.

Related posts

One comment on “Tiny confirmation modal dialog in Vanilla JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *