atrum Posted March 7, 2009 Share Posted March 7, 2009 Hello all, I have little experience with javascript, but I am trying to change that. Today it dawned on me that learning how to script in javascript would be alot easier if I could see all the errors my code is putting out. For example in PHP, if I wanted to see any errors that my code may produce, I would simply enter. ini_set('display_errors','On'); How can I do that for javascript? Thank you in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/148352-how-do-i-print-javascript-errors-to-the-screen/ Share on other sites More sharing options...
RichardRotterdam Posted March 7, 2009 Share Posted March 7, 2009 try installing the firebug plugin for firefox Quote Link to comment https://forums.phpfreaks.com/topic/148352-how-do-i-print-javascript-errors-to-the-screen/#findComment-778960 Share on other sites More sharing options...
darkfreaks Posted March 7, 2009 Share Posted March 7, 2009 if firebug on firefox doesn't solve your problems, http://www.jslint.com will debug your code error by error. if it is plain javascript and not a javascript library. Quote Link to comment https://forums.phpfreaks.com/topic/148352-how-do-i-print-javascript-errors-to-the-screen/#findComment-779134 Share on other sites More sharing options...
atrum Posted March 8, 2009 Author Share Posted March 8, 2009 Do you think something like this would work? onerror=handleErr var txt="" function handleErr(msg,url,l) { txt="There was an error on this page.\n\n" txt+="Error: " + msg + "\n" txt+="URL: " + url + "\n" txt+="Line: " + l + "\n\n" txt+="Click OK to continue.\n\n" alert(txt) return true } I dont really like that it comes up in a popup box. Is there a way to make this just write the error to the screen? Quote Link to comment https://forums.phpfreaks.com/topic/148352-how-do-i-print-javascript-errors-to-the-screen/#findComment-779867 Share on other sites More sharing options...
darkfreaks Posted March 8, 2009 Share Posted March 8, 2009 onerror=handleErr; var txt=""; function handleErr(msg,url,l) { txt="There was an error on this page.\n\n"; txt+="Error: " + msg + "\n"; txt+="URL: " + url + "\n"; txt+="Line: " + l + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); return true; } should use semicolons after your variables there also i hope you defined handleERR before you output it might have problems if you do not also should never use document.write or alert to output stuff. as its too global. call errors like this: var div = document.createElement('div'); div.className = 'foo'; div.appendChild(document.createTextNode('this is an error')); document.body.appendChild(div); Quote Link to comment https://forums.phpfreaks.com/topic/148352-how-do-i-print-javascript-errors-to-the-screen/#findComment-779879 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.