To replace the native alert with a nicer one, we can create a modal dialog using HTML, CSS, and JavaScript. Here's an example using plain JavaScript and the DOM manipulation:
First, create a modal dialog HTML structure with a message and two buttons, one for confirm and one for cancel:
202 chars8 lines
Then, add some CSS to style the modal dialog:
545 chars36 lines
Finally, add some JavaScript code to replace the native alert with the custom one:
index.tsx854 chars33 lines
Now, instead of using the native alert, we can call the showAlert
function with a message text and callbacks for the confirm and cancel buttons:
index.tsx159 chars6 lines
This will display a custom modal dialog with a message and two buttons, allowing the user to confirm or cancel the operation.
gistlibby LogSnag