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

100
Views
how to capture message shown in alert box

Here i need to get message that is displayed on alert box and click ok using javascript.

for example : alert("hello");

above that code displays message as hello which is coming from an other website I need to capture that message using javascript and script to get message and hit button.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can use this way:


function captureAlert() {
  // get all scripts
  var elem = document.scripts;

  // loop and check
  for (var i = 0, len = elem.length; i < len; i++) {

    var txt = elem[i].textContent.match(/alert\(['"]([^'"]+)['"]\)/);
    if (txt) { return txt[1]; } // if matched, return the alert value
  }
} 

about 4 years ago · Juan Pablo Isaza Report

0

You can just overwrite alert function.

var fn = alert;
alert = function(text) {
    document.write('<b>'+text+'</b>')
  alert = fn;
} 
<button onclick="alert('hello123')">Click</button>

about 4 years ago · Juan Pablo Isaza 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!