How to automatically press the confirmation button?

My script will click the image on the site. The image is anchored hrefand onclick href, but onclick href has a confirmation window that appears after clicking.
HTML onclick code:

onClick="this.href='link2';if (!confirm('Are you sure?')) { return false; }

How do I get a script to click OK in this confirmation window as soon as it appears?

I use this function to click the link with the image:

function click(elm) {
 var evt = document.createEvent('MouseEvents');
 evt.initMouseEvent('click', true, true, window, 0, 1, 1, 1, 1, false, false, false, false, 0, null);
 elm.dispatchEvent(evt);
}
click(picture element)
+5
source share
1 answer

confirm, true. , . , , , confirm .

var realConfirm=window.confirm;
window.confirm=function(){
  window.confirm=realConfirm;
  return true;
};
click(picture element);
+15

All Articles