debugging in javascript without alert dialog
20
To debug javascript code we use alert() whereever needed and it irritates you while alerts values inside a loop and other places where more alerts are being shown and you have to press the ok button to pass / proceed on.
here is a simple way to get rid of the alerts dialogs and get the values outputed into another debug window.
here is a simple way to get rid of the alerts dialogs and get the values outputed into another debug window.
var dwin = null;
function debug(msg) {
if ((dwin == null) || (dwin.closed)) {
dwin = window.open("","debugconsole","scrollbars=yes,resizable=yes,height=100,width=300");
dwin.document.open("text/html", "replace");
}
dwin.document.writeln('<br/>'+msg);
dwin.scrollTo(0,10000);
dwin.focus();
// dwin.document.close(); // uncomment this if you want to see only last message , not all the previous messages
}






I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
alerts aren't the recommended debug method for JS