Is there a way to simulate the Enter key on a confirm box?
The type of box created by confirm("Press a button!");
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>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