Simulate "Ok" Pressed In A Confirm Message?
Is there a way to simulate the Enter key on a confirm box? The type of box created by confirm('Press a button!');
Solution 1:
From JavaScript, running within the page, not really.
The standard browser confirm
dialog is modal and blocking. Absolutely no JS will run in the page while it is sitting there.
The closest you could come would be to override the function entirely.
function yes() {
document.body.appendChild(document.createTextNode("You said yes! "));
}
function sure() {
if (confirm("Are you sure?")) {
yes();
}
}
document.querySelector("button").addEventListener("click", sure);
window.confirm = function myConfirm() {
return true;
}
<button>Confirm</button>
Post a Comment for "Simulate "Ok" Pressed In A Confirm Message?"