1

There is website that alerts you with a text according to what you have done in the page.

I want to read that message with JavaScript so I can write some code according to what the page have shown in the popup text.

alert("message");

I just need to know what the "message" is!

The website that I'm trying to get message from is coded with asp.net.What should I do with that if it's impossible to read the message with JS.

Explosion
  • 178
  • 1
  • 12

2 Answers2

6

alert() is a global function, ie window.alert() so can be overwritten.

Most likely, you'll still want the alert, so you can keep a record of it before overwriting, giving:

window.old_alert = window.alert;
window.alert = function(msg) { 
    // Process the msg here
    console.log(msg); 

    // still show the original alert
    old_alert(msg); 
};
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
2

alert() function when executed is passed to the Browser to execute. Each browser executes it in its own way. So a way around is to override the alert() function itself.

Some javascript code on the page might be calling the alert() function. Maybe you can try to find the place in the code where it is called. The argument to alert() is what you need. You can override the default alert function using your own as described in: JavaScript: Overriding alert() . So you can do (as taken from the above answer):

(function(proxied) {
  window.alert = function() {
    // do something here
    // arguments is what holds what you want.
    return proxied.apply(this, arguments);
  };
})(window.alert);

@freedomn-m's answer is more relevant and apt. But you can use the answer for overriding alert() for more examples on how to do it.

Community
  • 1
  • 1
kumardeepakr3
  • 395
  • 6
  • 16
  • The code in your answer is more re-usable. Mine falls foul if multiple places reassign window.alert or the code is called twice. – freedomn-m Nov 12 '16 at 17:30