View Full Version : I have problems with onerror event handler on IE5
Hi, I use a lot of javascript functions in my web pages and i want to avoid that my web pages shows javascript errors when they throws an error.
I have taken the onerror Event Handler and put it into a script but it doesn't work on IE5.
Please, could you tell me, is there any way to control the errors for different navigators.
Thanks a lot! :)
the best way to do that is not to have errors in your scripts :)
joh6nn
09-19-2002, 10:33 PM
it's hard for us to make a call on your code, when we don't have it to look at. can we see the code you're using? complete with the error handler you have.
that's rigth, but it's better for me if I could control the errors to invoke my own function in this case.
thanks for all :)
thank for response John6nn, the code that i used is like this:
A type button call a javascript function, but in case this function doesn't exits i want to redirect to other function.
<input type="button" name="button1" value="button1" onclick="javascript:press2();">
I define the script before <body> on my jsp file:
<script type="text/javascript" language="JavaScript">
window.onerror=myErrorHandler
function myErrorHandler() {
alert('A customized error message');
return true;
}
</script>
It works in netscape but it doesn't work on IE5. Almost I tried with try...catch, and it works on IE5 but not on NS4.7.
thanks a lot.
I think the best thing to do is forget about error handling. Call the function as normal but use an if..else statement to get ie to call another funcition. For example:
<html>
<head>
<title>Example</title>
<script language="javascript" type="text/javascript">
<!-- ;
var ie5=(document.all && document.getElementById)
function b(){
alert("IE5")
}
function a() {
if(ie5)
b();
else
alert("FOO");
}
// -->
</script>
</head>
<body>
<a href="javascript: void a()">Call A</a>
</body>
</html>
hth
:) I think it's a good idea, 2 days ago i tried to capture the error with the function handle but i couldnīt. Now, I'll try your solution. Thank you for all, I'm really apreciate your help, thanks :)
adios
09-20-2002, 12:58 AM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function funcRedir(sPrimary, sBackup) {
if (typeof window[sPrimary] != 'undefined') eval(sPrimary + '()');
else if (typeof window[sBackup] != 'undefined') eval(sBackup + '()');
}
function backup() {
alert('backup');
}
//function shlebman() {
//alert('shlebman');
//}
</script>
</head>
<body>
<form>
<input type="button" name="button1" value="funcRedir('shlebman', 'backup')"
onclick="funcRedir('shlebman', 'backup')">
</form>
</body>
</html>
joh6nn
09-20-2002, 01:48 AM
you say it doesn't work in IE5. what doesn't work? the alert doesn't come up? what does it do, that it shouldn't be doing?
The alert come up when i press the button and the function doesn't exist. It seems that not recognized that onerror event handler. Do you think it's possible the configuration of the internet options??
thanks
sorry, i try to say that the javascript error come up, it seems that not recognized the onerror event handler, thanks
BrainJar
09-20-2002, 05:50 AM
You can use try-catch-finally blocks to trap errors:
try {
//code that might break.
alert("This code might have errors.");
}
catch (ex) {
//an exception occured, show it in an alert.
alert(ex);
}
finally {
//this code will run whether or not an exception occurs.
alert("This code always runs.");
}
joh6nn
09-20-2002, 06:22 AM
he needs backwards compatability. i can't see any reason why what he was trying originally, wouldn't work. which makes me think that maybe it is something in your settings, though for the life of me, i can't think what
thank you for your guidance, your advice was a great help to me, I adjust my code with the advice of all of us and it works now...thanks for all, nice to meet you
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.