tags:

views:

52

answers:

2

Hi all:

This might be a dumb question, but considering the following semi-pseudo code. How do I compare the string in windws.alert?

var alertCalled = false;
// I'm having trouble with the following line
if (windows.alert().text == 'specific string') {
    alertCalled = true;
}

Thanks.

A: 

You'd have to compare the string that is passed into the alert, e.g.

var message = "My alert message";
alert(message);
if (message == someOtherMessage) { /* do stuff */ }

The alert() function itself doesn't return anything.

cxfx
+1  A: 

alert function accepts a string as an input but does not echo it back. I am not sure but it might be possible to hook your own implementation of alert function to the native one. This worked in FireFox and IE8:

var alertCalled = false;
var originalAlert = window.alert;

window.alert = function( s )
{
    originalAlert( s );
    alertCalled = s == 'specific string';
}
Salman A
I've edited the post.
Salman A