PDA

View Full Version : Stop all javascript errors.


msimmons
07-15-2002, 09:31 PM
I have a javascript error that I want to hide from the users. I found this code online but is does not seem to work.

<script>
function stopErrors() {
return true;
}
window.onerror = stopErrors;
</script>


any ideas?

Thanks in advance,
Michael

ps. its been a long time since I have been here... the new look is awesome :)

msimmons
07-15-2002, 09:38 PM
Never mind... it seems to be working now... too many interuptions make it hard to get anything done.
Thanks
Michael

joh6nn
07-15-2002, 09:46 PM
actually, i'm pretty sure that should be:

<script>
function stopErrors() {
return false;
}
window.onerror = stopErrors;
</script>

msimmons
07-15-2002, 09:51 PM
no, its true like I have in the 1st post. I just tested it.

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function stopErrors() {
return true ;
}
window.onerror = stopErrors;
</script>
</HEAD>

<BODY>
<script>
alert(blah);
</script>
</BODY>
</HTML>


if you change it to false it will tell you that blah is undefined (because it is looking for a vaiable called blah).
Michael

joh6nn
07-15-2002, 10:01 PM
in what browser? i have a function like that on my website, to quietly catch all javascript errors and log them. i've tested the script in Mozilla and IE 5, 5.5, and 6, and it works fine in all of them, and it uses return false.

msimmons
07-15-2002, 10:03 PM
I'm using IE 5.5 sp2
Michael

joh6nn
07-15-2002, 10:19 PM
that is extremely interesting.

msimmons
07-15-2002, 10:21 PM
did you try my code that I posted? The full html page.
Michael

joh6nn
07-15-2002, 10:40 PM
yeah i did. it's weird. my function works in mozilla and in IE, but these couple of lines of code, both browsers throw errors if i set it to return false. i don't know. for the moment, i'm going to agree that you're right, and it's return true, but i don't know why. according to the Guide, it ought to be return false, and i am truely confused. i'm not gonna be around for the next two days, but when i get back, i will definitely be looking into this.

msimmons
07-15-2002, 10:43 PM
Let me know what you find :) I woulden't have posted the origonal post if I wasn't having problems so there must be something going on.
Thanks
Michael

glenngv
07-16-2002, 06:26 AM
To suppress JavaScript error dialogs when calling a function using onError, the function must return true. - www.devguru.com (http://www.devguru.com/Technologies/ecmascript/quickref/evhan_onerror.html)

Originally posted by joh6nn
yeah i did. it's weird. my function works in mozilla and in IE, but these couple of lines of code, both browsers throw errors if i set it to return false. i don't know. for the moment, i'm going to agree that you're right, and it's return true, but i don't know why. according to the Guide, it ought to be return false, and i am truely confused. i'm not gonna be around for the next two days, but when i get back, i will definitely be looking into this.

winlineau
07-16-2002, 06:48 AM
Why not use this:

http://www.codingforums.com/showthread.php?s=&threadid=123