开发者

compare string inside windows.alert

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') {
    alertCall开发者_运维问答ed = true;
}

Thanks.


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';
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜