Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Detect whether javascript threw an alert window (with javascript)

Reply
Thread Tools

Detect whether javascript threw an alert window (with javascript)

 
 
umdsasha@gmail.com
Guest
Posts: n/a
 
      08-24-2006
So, basically, I need to detect whether an alert window was thrown. I
can't find where it's thrown from but I need to disable a button only
if there were no alert windows thrown. Any ideas?

Thanks
Alex

 
Reply With Quote
 
 
 
 
guywmustang
Guest
Posts: n/a
 
      08-24-2006
If you're using a try{ } catch {}
Just add a variable in there to increment a counter... check to see if
the counter was > 0 ... How are you getting this alert to come up?


umdsa...@gmail.com wrote:
> So, basically, I need to detect whether an alert window was thrown. I
> can't find where it's thrown from but I need to disable a button only
> if there were no alert windows thrown. Any ideas?
>
> Thanks
> Alex


 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      08-24-2006
umdsa...@gmail.com wrote:
> So, basically, I need to detect whether an alert window was thrown. I
> can't find where it's thrown from but I need to disable a button only
> if there were no alert windows thrown. Any ideas?


Presumably, you are the one calling alerts so surely you can do this
some other way? Anyhow, all you do is assign a reference to
window.alert to some other global variable, then assign your own
function to window.alert - you *must* do this in the right order or
you'll lose your one and only reference to the window.alert function.

Disable the button by default, then enable it with your replacement
alert function. Of course users without JavaScript won't be able to
enable the button, but then they can't call alerts either.

e.g.

<script type="text/javascript">

// Function to run when alert called
function trapAlert(msg){
document.getElementById('aButton').disabled = false;
xAlert(msg);
}

// Assign reference to window.alert to another variable
var xAlert = window.alert;

// Re-assign window.alert
window.alert = trapAlert;

</script>

<input type="button" value="Button to enable" id="aButton" disabled
onclick="alert('I\'m working!!');">
<input type="button" value="Call an alert" onclick="alert('hey');">


--
Rob

 
Reply With Quote
 
Laurent Bugnion
Guest
Posts: n/a
 
      08-24-2006
Hi,

> umdsa...@gmail.com wrote:
>> So, basically, I need to detect whether an alert window was thrown. I
>> can't find where it's thrown from but I need to disable a button only
>> if there were no alert windows thrown. Any ideas?
>>
>> Thanks
>> Alex


guywmustang wrote:
> If you're using a try{ } catch {}
> Just add a variable in there to increment a counter... check to see if
> the counter was > 0 ... How are you getting this alert to come up?


try catch will catch an exception, not an alert window. You were
probably confused by the use of "thrown". alert windows are not thrown,
they are displayed

HTH,
Laurent


--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Windows: How to detect whether a Python app/script is runningin console/GUI mode? Tim Golden Python 1 07-27-2010 09:01 PM
Detect whether a key is being held before script execution? Thomas Wilson Ruby 3 04-14-2010 01:43 AM
Perl firewall test script - detect whether host not responding orfirewall rule not implemented inetquestion Perl Misc 0 05-06-2009 02:15 AM
Detect whether unicode string is Japanese Bob Marley Ruby 1 09-30-2008 05:15 PM
on click in popup window throws alert : need to avoid alert of postdata Ganesh ASP .Net 0 06-29-2007 06:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57