How do I take the cancel Button from the window.confirm?? Is there a way to taking it out and only the OK button will show up?
You can't, dialogs like confirm and alert are built into the browser and use native OS stylings. Is there a way we can do it in javascript? No, JavaScript cannot affect those dialogs. They are a part of the browser UI, not the webpage.
window. confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.
Change Button Label Using jQuery and CSS We have learned to change the label of the button of the confirm box by creating the custom confirm box. Also, we can use the custom libraries to style the confirm box. Now, we can set the button label in confirm box according to the confirmation message.
Confirm Box If the user clicks "Cancel", the box returns false.
If you don't want a cancel button, you might as well just use alert()
:
alert('This operation is not possible');
In beautiful ascii art it looks like this:
+-----------------------------------+
| |
| This operation is not possible |
| |
| +--------+ |
| | OK | |
| +--------+ |
+-----------------------------------+
When either OK is clicked or the dialog is dismissed, the next statement in your code will be executed.
If the next statement should be conditional, you'd have to stick with confirm()
unfortunately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With