jsDebugWin


jsDebugWin
Free Cross-browser Javascript Debugging Utility. (IE4+, NN4+, Opera7+, Firefox 0.9+)

A simple and light, yet powerful utility that allows you to print debug statements, view and modify page variables as well as execute functions and dynamically create new functions that has access to the running browser state.

Features

1. Real time DHTML/DOM manipulation
2. Dynamic function prototyping
3. Debug console
4. Javascript command history
5. Debug helper features (onerror, timers)


Quick links
  • Functions
  • Overview
  • Simple Demo
  • Feedback

    [Download]

  • If you want to try out this script WITHOUT downloading, copy and paste this into your code:
    (No guarantees that this link will continue to work)

    <script src="http://www.talkloud.com/jsdebugwin/jsdebugwin.js"></script>


    Functions

    • jsdebug(debug)
      Prints out any expressions defined in 'debug' on the debug window

    • jsTimedDebug(debug)
      Adds a timestamp to the debug output.

    • jsDelayedDebug(debug,millis)
      Delays refreshing of the debug window by 'millis' milliseconds. Ensures that the debug window
      does not interfere with script functions. Useful when executing multiple debug statements within a
      short time frame (ie. in loops).

    • jsGetElem(elemId)
      A debugging shortcut to the document.all and document.getElementById functions.
      ie. foo = jsGetElem("mydiv") instead of foo = document.getElementById("mydiv");

    • jsDebugError(msg,url,linenumber)
      A Javascript error trap routine. (to enable: window.onerror = jsDebugError)
      Sends Javascript errors to the debug window.
      IE: Script Debugging needs to be turned off (Tools -> Internet Options -> Advanced)
      NN7x: Does not trap errors entered in the debug input box.
      Opera: Error trapping feature not supported.


    Overview

    Setup
    Setting up and running jsDebugWin is easy.

    1. Download the script to the same folder as the page you are trying to debug, and add this statement above the <body> tag within your page:
       <script src="jsdebugwin.js"></script>
    
    2. a) To manually launch the window, just type this in the url address input at the top of your browser:
           javascript:jsdebug()
    
         or put this as a link in your page:
           <a href="javascript:jsdebug()">[launch jsDebugWin]</a>
    
       b) To automatically launch the debug window, call jsdebug() within your code:
         <script>
            jsdebug();
         </script>
    
    To disable the debug window, add this statement below the jsdebugwin.js source statement:
         <script>
            jsDebugOK = false;
         </script>
    

    Basic stuff
    Small input:


    Ideal for short statements.
    To enter quick successive statements, press the Enter key after each statement instead of clicking the "Run" button.
    Large input:

    For more complicated debug statements.
    When doing intensive debugging via the debug input box, it is recommended that you use IE5+ and click on the "Trap error" option. This will trap any syntax errors. (The script is unable to trap input box errors on Netscape and Opera).
    Do not declare variables within the input box with var
    Variables that are declared with var has local scope and will not be accessible after the execution call. Only use var if you want the variable to exist only within the execution "block" (ie. for loops and stuff)

     Instead of:
        var color = "red";
     do
        color = "red";
    


    More Advanced stuff
    Dynamic function prototyping
    You can prototype functions by declaring new functions within the input box. The functions will have the same access to the variables in the page as all other functions.

      Example:
        addMe = function(a,b){
          jsdebug("result = "+(a+b));
        }
    
    You can then invoke the function like any other function from the input box (ie. addMe(5,10) )

    Hint: You can also see the code of any existing functions by entering the function name without the parenthesis '()' in a jsdebug() statement:
       jsdebug(addMe);
    
    Similarly, you can override existing (non-browser) functions by redeclaring the functions. So for example, you notice a bug with a function, you could temporarily modify the function by redeclaring the function within the input box.



    Simple Demo (will have a better demo soon)




    Change the color of the box to: Red, Green

    The changeColor code is displayed below:
      <script>
        changeColor = function(color){
          var thediv = document.getElementById("demodiv");
          thediv.style.backgroundColor = color;
          jsdebug("The new color is: "+color);
        }
      </script>
    
    Try calling the changeColor function from the debug input box by using either literal colors (ie. "red") or hex colors (ie. "0000aa"):

       changeColor("blue");
    


    Feedback and Updates

    Thank you for using jsDebugWin and I appreciate you taking the time to get back to me on any bugs or suggestions!
    Let me know if there are any major browsers that this does not work with and I'll take a look into it.

    To get in touch with me:








    For more scripts visit:
  • ScriptSearch.com
  • HotScripts.com