PDA

View Full Version : No Errors JavaScript



Jack
05-10-2006, 06:28 AM
If you get an error on one of your pages and don't know how to fix it you could try simply placing the following at the very bottom of your page.



<SCRIPT LANGUAGE="JavaScript">

function CC_noErrors() {
return true;
}
window.onerror = CC_noErrors;
// -->
</SCRIPT>


:D

jscheuer1
05-10-2006, 07:06 AM
But then you'd never know the error of your ways . . .

Twey
05-10-2006, 04:38 PM
Better expressed as:
<script type="text/javascript">
window.onerror = null;
</script>However, it's still a stupid idea. It wouldn't magically cause the script to work, so you'd have a broken script with no apparent cause.
It's better for users to see errors and report them to you; that way, you've no problem.
<script type="text/javascript">
window.onerror = function(e, url, line) {
var message = "An error occured in " + url + ", line " + line + ", using " + navigator.userAgent + ":\n\t" + e.toString().replace(/\n/g, "\n\t"),
subject = "An error occurred in your site",
address = "youATyourdomainDOTcom".replace("AT", "@").replace("DOT", "."),
response = window.confirm("An error has occurred. Would you like to report it? On clicking OK, an email containing all the necessary information will be composed and given to you for review.");
if(response) {
window.location.href = "mailto:" + address + "?Subject=" + escape(subject) + "&body=" + escape(message);
return true;
} else return false;
}
</script>Untested.