Basically, I need a sanity check.
Assuming this code:
prompt("Yes or no?")
The user must click an answer here. There isn't a way in Javascript to "answer" the question for the user... correct? Everything I know screams impossible... but wanted to triple check here first.
Nope.
prompt()
immediately puts up a modal dialog box, and blocks all further script execution until a value is entered. There is no opportunity to intercept or handle at any point, because no code is allowed to run while it's up.
Perhaps you want a different way to put up a dialog box that's less intrusive like jQuery UI Dialog's
Wait, so you seem more concerned that it could be tampered with and you don't want it to be?
If so, my answer stands as true but there are other ways to get around it. For instance, you can override the prompt()
function before it runs to do whatever you want. This snippet would prevent any prompt from appearing and hardcode a specific return value.
window.prompt = function() { return 'spoofed' };
var name = prompt("What's your name?"); // no prompt appears
console.log(name); //=> 'spoofed'
Without knowing what you are trying to accomplish, it's hard to advise how to do it instead. But if you want a prompt that will answer the question "are you a human?", it won't be reliable as it's easily bypassed.
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