473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Detect whether javascript threw an alert window (with javascript)

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

Aug 24 '06 #1
3 9549
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
Aug 24 '06 #2
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

Aug 24 '06 #3
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
Aug 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: David McCulloch | last post by:
QUESTION-1: How can I detect if Norton Internet Security is blocking pop-ups? QUESTION-2a: How could I know if a particular JavaScript function has been declared? QUESTION-2b: How could I...
6
by: hb | last post by:
Hi, Would you please tell me how to detect if the client's browser is closed? I need such event to trigger a database modification. Thank you hb
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
8
by: Luke Matuszewski | last post by:
I have read all posts about how to detect that url have changed to new page and trigger the event handler then eg. function aidLogout(evt) { if(evt) { /* maybe via analyse of evt object i can...
2
by: sylvain | last post by:
is there a simple way to detect a web window closing when the user hit the X of the browser ? I want to display a message to the user when he goes out of my web page. I try to detect it by using...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
10
by: Pugi! | last post by:
I create elements dynamically on a webpage using AJAX. I add events (like onclick). Everything works fine I can retrace the origin of the event, the parentnode, ... but now I have to put a layer (a...
3
by: victorzou | last post by:
hi all ; I am new guy! I need to know whether the webpage is the top active IE window with javascript in the webpage,when I open 2 or more IE window. tks in advance! victor.zou
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.