Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Detectar si se muestra una alerta o confirmación en una página

¿Hay alguna forma de usar JavaScript o jQuery para detectar si se muestra un cuadro de confirmación o alerta?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Si desea ejecutar algún código cuando se activa una alert() , podría intentar algo como esto:

Solo probé en Chrome, por lo que no estoy seguro de la compatibilidad del navegador.

Ejemplo: http://jsfiddle.net/Q785x/1/

 (function() { var _old_alert = window.alert; window.alert = function() { // run some code when the alert pops up document.body.innerHTML += "<br>alerting"; _old_alert.apply(window,arguments); // run some code after the alert document.body.innerHTML += "<br>done alerting<br>"; }; })(); alert('hey'); alert('you'); alert('there');

Por supuesto, esto solo le permite ejecutar código antes y después de una alerta. Como señaló @kander, la ejecución de javascript se detiene mientras se muestra la alerta.

over 4 years ago · Santiago Trujillo Report

0

No no hay. Puede verificar que el valor de retorno de un comando de confirm sea true o false , pero no puede verificar si existe visualmente.

Estas cosas son parte del navegador, no parte del DOM. Estoy seguro de que hay un truco sucio que funciona para IE porque es un hijo bastardo del sistema operativo Windows.

over 4 years ago · Santiago Trujillo Report

0

Podrías hacer esto si quieres...

 (function () { // remember the normal alert var oldAlert = (function(){ return this.alert; }()), oldConfirm = (function(){ return this.confirm; }()); // inject ourself into the window.alert and window.confirm globals alert = function (msg) { oldAlert.call(document, msg); document.onAlert(msg); }; confirm = function (msg) { var result = oldConfirm.call(document, msg); document.onConfirm(msg, result); return result; }; // these just chill and listen for events document.onAlert = function (msg) { window.console && console.log('someone alerted: ' + msg); }; document.onConfirm = function (msg) { window.console && console.log('someone was asked: ' + msg); window.console && console.log('and they answered: ' + (msg ? 'yes' : 'no')); }; }());

La desventaja de esto es que

  • está pirateando un método host de un navegador (cosas que normalmente no debería hacer - http://perfectionkills.com/whats-wrong-with-extending-the-dom/ )
  • deberías estar mejor haciendo un seguimiento de tu uso de alert() confirm() , jaja
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!