I could be wrong but I do not think this is possible with an alert box. It is a pre-defined function in javascript and I do not think you can modify it's controls.
What you could do instead of an alert is to display a positioned DIV on the page with your message and trap for key presses while it is displaying. You would have much more control over the style of the box and it's controls doing it this way.
At my age I still learn something new every day, but I forget two others.
Look at this link for an alternative type of alert box. It does contain the code to trap any keypress but that can be added in if this approach is acceptible.
At my age I still learn something new every day, but I forget two others.
You could set an onkeypress event in the document body tag like:
Code:
<body onkeypress="keyPressed();">
Now the trick is, you need to know when the alert message is displayed on the screen. So you have a variable declared globally:
var alrtDisp = false; //Declare this globally outside of function.
Then when your function displays the div with the message you can set the flag like:
alrtDisp = true;
Then the function called from the onkeypress event has to check that flag to see if it is true or false and ignore the keypress if it was false.
Code:
function keyPressed() {
if (alrtDisp)
//Alert is being displayed and key pressed
//so hide the alert div and then reset the alrtDisp
//value to false.
}
At my age I still learn something new every day, but I forget two others.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.