debugging in javascript without alert dialog





20
Date Submitted Mon. Sep. 25th, 2006 1:59 AM
Revision 1 of 1
Syntax Master sundaramkumar
Tags JavaScript
Comments 3 comments
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.


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
}


 
add the above code in you page first. Try the following for example. for(var i=0;i<10;i++){ debug(i); //... you other statements here } this will open a new debug window and show/ouputs the value of i

Comments

Comments A Great Boon . . .
Tue. Sep. 26th, 2006 1:15 PM    Scripter sehrgut
Comments reopen
Sun. Oct. 29th, 2006 12:01 PM    Scripter SCoon
Comments why alerts?
Fri. Jan. 12th, 2007 4:55 PM    Newbie crashoverride

Voting