Reputation: 27422
I have a JavaScript alert button that appears on the website when a user is going to proceed to a signup page.
It looks something like this
Would you like to proceed to the signup page?
< OK > < Cancel >
Would it be possible to add a third button to the alert so that it looks like
Would you like to proceed to the signup page?
< More Info > < OK > < Cancel >
Upvotes: 16
Views: 39793
Reputation: 1653
Nowdays, you can use an HTML dialog
element.
<dialog open>
<p>Greetings, one and all!</p>
<button>Ok</button><button>Maybe</button><button>Cancel</button>
</dialog>
And do what you want with it.
document.querySelectorAll('button').forEach($button =>
$button.onclick = () => document.querySelector('dialog').removeAttribute('open'))
https://jsfiddle.net/6nus2zt4/1/
Hope this helps to future generations :)
Upvotes: 8
Reputation: 1417
however you can use confirm function.. but NOT three buttons.
var r=confirm("Press a button!");
if (r==true)
{
x="You pressed OK!";
}
else
{
x="You pressed Cancel!";
}
Upvotes: 4
Reputation: 550
Unfortunately, I don't think you can change the number of buttons in an alert box. (At least not in any browser that I know of.) You can use one of the many modal dialog scripts that are out on the net. Something like Eric Martin's SimpleModal Dialog for jquery would probably work.
They basically take a div and style it up with css and javascript to mimic a dialog box.
Upvotes: 3
Reputation: 888213
No.
You need to use a custom modal dialog, such as jQuery UI Dialog.
Upvotes: 17