javascript trace window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    javascript trace window

    Can anyone point me to some code that will display messages, in a seperate
    window, from javascipt. ie effectively a trace window?


    TIA

    Chris


  • Lee

    #2
    Re: javascript trace window

    Chris said:[color=blue]
    >
    >Can anyone point me to some code that will display messages, in a seperate
    >window, from javascipt. ie effectively a trace window?[/color]

    alert(msg);

    Comment

    • Robert

      #3
      Re: javascript trace window

      In article <PTtVc.475$Nq1. 340@newsfe6-gui.ntli.net>, "Chris" <.@>
      wrote:
      [color=blue]
      > Can anyone point me to some code that will display messages, in a seperate
      > window, from javascipt. ie effectively a trace window?
      >[/color]


      This should help. Just run the file. The function debugOut displays a
      message in the popup window created by startDebug. Be sure to enable
      popup windows. My favorite line is:
      debugOut("myVar = " + myVar);

      alert is a point because you have to press enter and you loss was was
      displayed.

      Robert

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <title>javascri pt debug routines and tester</title>

      <script type="text/javascript">

      function startDebug(debu gMode) {
      startDebug.debu gMode = debugMode;
      if (startDebug.deb ugMode == true) {
      var debugWindowName =
      document.URL.su bstr(document.U RL.lastIndexOf( "/")+1);
      var thePosition = debugWindowName .indexOf(".");
      if (thePosition > 0)
      { debugWindowName = debugWindowName .substr(0,thePo sition); }
      startDebug.newW indow = window.open("", debugWindowName ,
      "scrollbars=yes ,resizable=yes, width=700,heigh t=500");
      startDebug.newW indow.document. writeln(
      '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' +
      '//EN">' + "<html><header> <title>Window " + debugWindowName +
      "</title></header><body><p >The debug information " +
      "that follows was generated on " + Date() + "</p>");
      }
      }


      // Example invocation & print: DumpProperties( document,'docum ent');

      function dumpProperties( obj, obj_name)
      {
      var i;
      // Example invocation & print: DumpProperties( document,'docum ent');
      if (startDebug.deb ugMode == true )
      {
      debugOut('In DumpProperties. obj=' + obj_name);
      for (i in obj)
      {

      try
      {
      debugOut(obj_na me + "." + i + " = " + obj[i]);
      }
      catch(e)
      {
      debugOut("Error writing out structure. Was " + e + " for " + i);
      }


      }
      }
      }

      function dumpPropertiesS orted(obj, obj_name)
      {
      var i;
      var sorted = [ ];
      var objCount = 0;

      if (startDebug.deb ugMode == true )
      {
      debugOut('In DumpProperties. obj=' + obj_name);

      for (i in obj)
      {
      sorted[objCount++] = i;
      }

      sorted.sort();

      for ( i=0; i <sorted.lengt h; i++)
      {
      try
      {
      debugOut(obj_na me + "." + sorted[i] + " = " +
      obj[sorted[i]]);
      }
      catch(e)
      {
      debugOut("Error writing out structure. Was " +
      i + " for " + sorted[i]);
      }
      }

      } // if we are debugging.

      }

      function debugOut(obj)
      {
      var theString = "" + obj;
      if (startDebug.deb ugMode == true ) {
      // Ordering of the replacement string is important
      var theString = theString.repla ce(
      /&/g, "&amp;").replac e(
      /</g, "&lt;").replace (
      />/g, "&gt;");
      // theString = theString.repla ce(/ /g, "&nbsp;");
      startDebug.newW indow.document. writeln(theStri ng + "<br>");
      }
      }



      </SCRIPT>
      </head>
      <body>
      <script>
      var test = {a:1, c:3, b:2};
      var testBoolean = true;

      startDebug(true );

      dumpProperties( test,"test");
      debugOut("displ ay the test object in sorted form");
      dumpPropertiesS orted(test,"tes t");
      debugOut(testBo olean);
      debugOut("<b>&< \/b>");
      </script>
      <p>Debug routines and testing.</p>
      </body>
      </html>

      Comment

      • Chris

        #4
        Re: javascript trace window

        Thanks v much, works a treat

        one oddity though
        in Opera 7.51 all OK
        in IE 6 I had to alter the following

        //startDebug.newW indow = window.open("", debugWindowName ,
        "scrollbars=yes ,resizable=yes, width=700,heigh t=500");
        startDebug.newW indow = window.open("", null,
        "scrollbars=yes ,resizable=yes, width=700,heigh t=500");

        as it was throwing the following error

        ---------------------------
        Error
        ---------------------------
        A Runtime Error has occurred.
        Do you wish to Debug?

        Line: 15
        Error: Invalid argument.
        ---------------------------
        Yes No
        ---------------------------



        Again my thanks

        Chris


        "Robert" <rccharles@my-deja.com> wrote in message
        news:rccharles-22A98A.23443320 082004@news6.we st.earthlink.ne t...[color=blue]
        > In article <PTtVc.475$Nq1. 340@newsfe6-gui.ntli.net>, "Chris" <.@>
        > wrote:
        >[color=green]
        > > Can anyone point me to some code that will display messages, in a[/color][/color]
        seperate[color=blue][color=green]
        > > window, from javascipt. ie effectively a trace window?
        > >[/color]
        >
        >
        > This should help. Just run the file. The function debugOut displays a
        > message in the popup window created by startDebug. Be sure to enable
        > popup windows. My favorite line is:
        > debugOut("myVar = " + myVar);
        >
        > alert is a point because you have to press enter and you loss was was
        > displayed.
        >
        > Robert
        >
        > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        > <html>
        > <head>
        > <title>javascri pt debug routines and tester</title>
        >
        > <script type="text/javascript">
        >
        > function startDebug(debu gMode) {
        > startDebug.debu gMode = debugMode;
        > if (startDebug.deb ugMode == true) {
        > var debugWindowName =
        > document.URL.su bstr(document.U RL.lastIndexOf( "/")+1);
        > var thePosition = debugWindowName .indexOf(".");
        > if (thePosition > 0)
        > { debugWindowName = debugWindowName .substr(0,thePo sition); }
        > startDebug.newW indow = window.open("", debugWindowName ,
        > "scrollbars=yes ,resizable=yes, width=700,heigh t=500");
        > startDebug.newW indow.document. writeln(
        > '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' +
        > '//EN">' + "<html><header> <title>Window " + debugWindowName +
        > "</title></header><body><p >The debug information " +
        > "that follows was generated on " + Date() + "</p>");
        > }
        > }
        >
        >
        > // Example invocation & print: DumpProperties( document,'docum ent');
        >
        > function dumpProperties( obj, obj_name)
        > {
        > var i;
        > // Example invocation & print: DumpProperties( document,'docum ent');
        > if (startDebug.deb ugMode == true )
        > {
        > debugOut('In DumpProperties. obj=' + obj_name);
        > for (i in obj)
        > {
        >
        > try
        > {
        > debugOut(obj_na me + "." + i + " = " + obj[i]);
        > }
        > catch(e)
        > {
        > debugOut("Error writing out structure. Was " + e + " for " + i);
        > }
        >
        >
        > }
        > }
        > }
        >
        > function dumpPropertiesS orted(obj, obj_name)
        > {
        > var i;
        > var sorted = [ ];
        > var objCount = 0;
        >
        > if (startDebug.deb ugMode == true )
        > {
        > debugOut('In DumpProperties. obj=' + obj_name);
        >
        > for (i in obj)
        > {
        > sorted[objCount++] = i;
        > }
        >
        > sorted.sort();
        >
        > for ( i=0; i <sorted.lengt h; i++)
        > {
        > try
        > {
        > debugOut(obj_na me + "." + sorted[i] + " = " +
        > obj[sorted[i]]);
        > }
        > catch(e)
        > {
        > debugOut("Error writing out structure. Was " +
        > i + " for " + sorted[i]);
        > }
        > }
        >
        > } // if we are debugging.
        >
        > }
        >
        > function debugOut(obj)
        > {
        > var theString = "" + obj;
        > if (startDebug.deb ugMode == true ) {
        > // Ordering of the replacement string is important
        > var theString = theString.repla ce(
        > /&/g, "&amp;").replac e(
        > /</g, "&lt;").replace (
        > />/g, "&gt;");
        > // theString = theString.repla ce(/ /g, "&nbsp;");
        > startDebug.newW indow.document. writeln(theStri ng + "<br>");
        > }
        > }
        >
        >
        >
        > </SCRIPT>
        > </head>
        > <body>
        > <script>
        > var test = {a:1, c:3, b:2};
        > var testBoolean = true;
        >
        > startDebug(true );
        >
        > dumpProperties( test,"test");
        > debugOut("displ ay the test object in sorted form");
        > dumpPropertiesS orted(test,"tes t");
        > debugOut(testBo olean);
        > debugOut("<b>&< \/b>");
        > </script>
        > <p>Debug routines and testing.</p>
        > </body>
        > </html>[/color]


        Comment

        • Robert

          #5
          Re: javascript trace window

          "Chris" <.@> wrote in message news:<fmFVc.364 $tc5.68@newsfe6-gui.ntli.net>.. .[color=blue]
          > Thanks v much, works a treat[/color]

          Glad to have helped out.
          [color=blue]
          >
          > one oddity though[/color]

          ;-)


          [color=blue]
          > in IE 6 I had to alter the following
          >[/color]
          [color=blue]
          > Error: Invalid argument.
          > ---------------------------[/color]

          I suspect you had a special character in your file name. I am using
          the filename as the debug window name. Web browsers seem to take the
          input file name and use the escape function on them. For instance,
          the space character in a file name is converted to %20. The IE
          version of window.opend doesn't accept a % as part of the debug window
          name.

          I have posted a new version of the file below. I filter out the % and
          all the other special characters.

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
          <head>
          <title>javascri pt debug routines and tester</title>

          <script type="text/javascript">

          // Popup the debug window.
          // You need to have enabled popup windows

          function startDebug(debu gMode) {
          startDebug.debu gMode = debugMode;

          if (startDebug.deb ugMode == true) {
          var debugWindowName =
          document.URL.su bstr(document.U RL.lastIndexOf( "/")+1);
          var thePosition = debugWindowName .indexOf(".");
          if (thePosition > 0)
          { debugWindowName = debugWindowName .substr(0,thePo sition); }
          // Get rid of special characters because IE won't accept them

          debugWindowName =
          debugWindowName .match(/[a-zA-Z0-9]/g).join("");

          try
          { startDebug.newW indow = window.open("", debugWindowName ,
          "scrollbars=yes ,resizable=yes, width=700,heigh t=500"); }
          catch(e)
          { debugWindowName = "debug";
          startDebug.newW indow = window.open("", debugWindowName ); }

          startDebug.newW indow.document. writeln(
          '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' +
          '//EN">' + "<html><header> <title>Window " + debugWindowName +
          "</title></header><body><p >The debug information " +
          "that follows was generated on " + Date() + "</p>");
          }
          }

          // Example invocation & print: DumpProperties( document,'docum ent');

          function dumpProperties( obj, obj_name)
          {
          //Example invocation & print: DumpProperties( document,'docum ent');
          if (startDebug.deb ugMode == true )
          {
          debugOut('In DumpProperties. obj=' + obj_name);
          for (var i in obj)
          {
          try
          { debugOut(obj_na me + "." + i + " = " + obj[i]); }
          catch(e)
          { debugOut("Error writing out structure. Was " +
          e + " for " + i); }
          }
          }
          }

          function dumpPropertiesS orted(obj, obj_name)
          {
          var i;
          var sorted = [ ];
          var objCount = 0;

          if (startDebug.deb ugMode == true )
          {
          debugOut('In DumpProperties. obj=' + obj_name);

          for (i in obj)
          {
          sorted[objCount++] = i;
          }

          sorted.sort();

          for ( i=0; i <sorted.lengt h; i++)
          {
          try
          { debugOut(obj_na me + "." + sorted[i] + " = " +
          obj[sorted[i]]); }
          catch(e)
          { debugOut("Error writing out structure. Was " +
          i + " for " + sorted[i]); }
          }

          } // if we are debugging.
          }

          function debugOut(obj)
          {
          var theString = "" + obj;
          if (startDebug.deb ugMode == true ) {
          // Ordering of the replacement string is important
          var theString = theString.repla ce(
          /&/g, "&amp;").replac e(
          /</g, "&lt;").replace (
          />/g, "&gt;");
          // theString = theString.repla ce(/ /g, "&nbsp;");
          startDebug.newW indow.document. writeln(theStri ng + "<br>");
          }
          }



          </SCRIPT>
          </head>
          <body>
          <script>
          var test = {a:1, c:3, b:2};
          var testBoolean = true;

          startDebug(true );

          dumpProperties( test,"test");
          debugOut("displ ay the test object in sorted form");
          dumpPropertiesS orted(test,"tes t");
          debugOut(testBo olean);
          debugOut("<b>&< \/b>");

          var myString = "abcDEF Ghi~123~ *&^ end";
          debugOut("myStr ing = " + myString +
          " compressed: " +
          escape(myString .match(/[a-zA-Z0-9]/g).join("") ) );

          </script>
          <p>Debug routines and testing.</p>
          </body>
          </html>

          Comment

          • Lee

            #6
            Re: javascript trace window

            Robert said:
            [color=blue]
            > startDebug.newW indow = window.open("", debugWindowName ,
            > "scrollbars=yes ,resizable=yes, width=700,heigh t=500");
            > startDebug.newW indow.document. writeln(
            > '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' +
            > '//EN">' + "<html><header> <title>Window " + debugWindowName +
            > "</title></header><body><p >The debug information " +
            > "that follows was generated on " + Date() + "</p>");[/color]

            Opening and then writing into a window is unreliable.
            It's much safer to have the new window load the content when it's ready.

            function log(msg) {
            globalHTML="<ht ml><body><p>"+m sg+"</p></body></html>";
            window.open("ja vascript:opener .globalHTML",
            "logWindow" ,
            "width=400,heig ht=200,resizabl e").focus();
            }

            Since the window opens immediately, there's really no point in displaying the
            date.

            Comment

            • Tom

              #7
              Re: javascript trace window

              How can you get this to autoscroll to the trace line just entered?

              Comment

              Working...