Click OK button of window.confirm

Asked

Viewed 395 times

1

Good afternoon, when I click on a button opens a window.confirm obviously it has an OK and CANCEL, I wonder if there is a way for me to click on this OK button as soon as it opens with javascript?

HMTL

<a href="/excluir/recado/5735526/b3dd743495e9e826c7703b7f3d26a545" onclick="if(!confirm('Tem certeza que deseja excluir esse recado?')) return false;" class="btn-orkut">excluir<*a>

Javascript:

document.getElementsByTagName("a")[0].click();

Javascript works well, but by default it opens the confirm window, and in this I have to keep clicking OK I would like to know if there is this possibility of javascript to be clicking on OK. grateful

2 answers

1

I wonder if there’s a way I can click this OK button as soon as it opens

There is no.

Native browser windows are very limited in terms of interaction. This is for security reasons, to watch over the user. If this were possible there would be no security for the user to respond to what they want in that confirmation request.

  • Grateful for the answer ! So I can only keep where I was. Thank you

  • 1

    I think, in this case, it is not so much a security issue, since whoever programmed the script to display the confirmation window could simply call the code from the "Yes" button directly if they wanted to. In fact, the need for security is until the opposite-- if the script keeps calling many such windows, the browser may even provide an option to block them.

0

I know it’s an old question, but the kind of Gambita way I do is this: Puppeteer:

page.evaluate(() => window.confirm = function() {});

in other systems where I edit the JS is the same thing, more or less that:

browser.evaluateScriptAsync(@" Teste function() { window.confirm = function() {}} Teste()");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.