Runtime Error...Can't Figure Out Why...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LayneMitch via WebmasterKB.com

    Runtime Error...Can't Figure Out Why...

    Hello.

    This is a reference file from a book I read in which the core subject is the
    use of 'event listeners'.

    I'm trying to load the file in Firefox and it's giving me an error message:

    Line: 5
    Char: 1
    Error: 'document' is undefined
    Code: 800A1391
    Source: Microsoft JScript Runtime Error

    I need this file to work because it's the reference file for all of my coding.
    Here's the contents of the file here.

    var Core={};

    // W3C DOM 2 Events model

    if (document.addEv entListener)
    {
    Core.addEventLi stener = function(target , type, listener)
    {
    target.addEvent Listener (type, listener, false);
    };


    Core.removeEven tListener = function(target , type, listener)
    {
    target.removeEv entListener(typ e, listener, false);
    };

    Core.preventDef ault = function(event)
    {
    event.preventDe fault();
    };

    Core.stopPropag ation = function(event)
    {
    event.stopPropa gation();
    };
    }

    // Internet Explorer Events model

    else if (document.attac hEvent)
    {
    Core.addEventLi stener = function(target , type, listener)
    {
    // prevent adding the same listener twice, since DOM 2

    // Events ignores duplicates like this

    if (Core._findList ener(target, type, listener) != -1)
    return;

    // listener2 calls listener as a method of target in one of

    // two ways, depending on what this version of IE supports,

    // and passes it the global event object as an argument

    var listener2 = function()
    {
    var event = window.event;

    if (Function.proto type.call)
    {
    listener.call(t arget, event);
    }

    else
    {
    target._current Listener = listener;
    target._current Listener(event)
    target._current Listener = null;
    }
    };


    // add listener2 using IE's attachEvent method
    target.attachEv ent("on" + type, listener2);

    // create an object describing this listener so we can

    // clean it up later

    var listenerRecord =
    {
    target: target,
    type: type,
    listener: listener,
    listener2: listener2
    };

    // get a reference to the window object containing target

    var targetDocument = target.document || target;
    var targetWindow = targetDocument. parentWindow;

    // create a unique ID for this listener

    var listenerId = "1" + Core._listenerC ounter++;

    // store a record of this listener in the window object

    if (!targetWindow. _allListeners)
    targetWindow._a llListeners = {};
    targetWindow._a llListeners[listenerID] = listenerRecord;

    // store this listener's ID in target

    if (!target._liste ners) target._listene rs = [];
    target._listene rs[target._listene rs.length] = listenerId;

    // set up Core._removeAll Listeners to clean up all

    // listeners on unload

    if (!targetWindow. _unloadListener Added)
    {
    targetWindow._u nloadListenerAd ded = true;
    targetWindow.at tachEvent(
    "onunload", Core._removeAll Listeners);
    }
    };


    Core.removeEven tListener = function(target , type, listener)
    {
    // find out if the listener was actually added to target

    var listenerIndex = Core._findListe ner(
    target, type, listener);
    if (listenerIndex == -1) return;

    // get a reference to the window object containing target

    var targetDocument = target.document || target;
    var targetWindow = targetDocument. parentWindow;

    // obtain the record of the listener from the window object

    var listenerId = target._listene rs[listenerIndex];
    var listenerRecord =
    targetWindow._a llListeners[listenerId];

    // remove the listener, and remove its ID from target

    target.detachEv ent("on" + type, listenerRecord. listener2);
    target._listene rs.splice(liste nerIndex, 1);

    // remove the record of the listener from the window object

    delete targetWindow._a llListeners[listenerId];

    };

    Core.preventDef ault = function(event)
    {
    event.returnVal ue = false;
    };

    Core.stopPropag ation = function(event)
    {
    event.cancelBub ble = true;
    };

    Core._findListe ner = function(target , type, listener)
    {
    // get the array of listener IDs added to target

    var listeners = target._listene rs;
    if (!listeners) return -1;

    // get a reference to the window object containing target

    var targetDocument = target.document || target;
    var targetWindow = targetDocument. parentWindow;

    // searching backward (to speed up onunload processing),

    // find the listener

    for (var i = listeners.lengt h - 1; i >= 0; i--)
    {
    // get the listener's ID from target

    var listenerId = listeners[i];

    // get the record of the listener from the window object

    var listenerRecord =
    targetWindow._a llListeners[listenerId];

    // compare type and listener with the retrieved record

    if (listenerRecord .type == type &&
    listenerRecord. listener == listener)
    {
    return i;
    }
    }
    return -1;
    };

    Core._removeAll Listeners = function()
    {
    var targetWindow = this;

    for (id in targetWindow._a llListeners)
    {
    var listenerRecord = targetWindow._a llListeners[id];
    listenerRecord. target.detachEv ent(
    "on" + listenerRecord. type, listenerRecord. listener2);
    delete targetWindow._a llListeners[id];
    }
    };

    Core._listenerC ounter = 0;

    }


    Core.addClass = function(target , theClass)
    {
    if (!Core.hasClass (target, theClass))
    {
    if (target.classNa me == " ")
    {
    target.classNam e = theClass;
    }

    else
    {
    target.classNam e += " " + theClass;
    }
    }

    };


    Core.getElement sByClass = function(theCla ss)
    {
    var elementArray = [];

    if (typeof document.all != "undefined" )
    {
    elementArray = document.all;
    }

    else
    {
    elementArray = document.getEle mentsByTagName( "*");
    }

    var matchedArray = [];
    var pattern = new RegExp("(^| )" + theClass + "( |$)");

    for (var i = 0; i < elementArray.le ngth; i++)
    {
    if (pattern.test(e lementArray[i].className))
    {
    matchedArray[matchedArray.le ngth] = elementArray[i];
    }
    }

    return matchedArray;

    };


    Core.hasClass = function(target , theClass)
    {
    var pattern = new RegExp("(^| )" + theClass + "( |$)");

    if (pattern.test(t arget.className ))
    {
    return true;
    }

    return false;

    };


    Core.removeClas s = function(target , theClass)
    {
    var pattern = new RegExp("(^| )" + theClass + "( |$)");

    target.classNam e = target.classNam e.replace(patte rn, "$1");
    target.classNam e = target.classNam e.replace(/ $/, " ");
    };


    Core.getCompute dStyle = function(elemen t, styleProperty)
    {
    var computedStyle = null;

    if (typeof element.current Style != "undefined" )
    {
    computedStyle = element.current Style;
    }

    else
    {
    computedStyle =
    document.defaul tView.getComput edStyle(element , null);
    }

    return computedStyle[styleProperty];

    };

    Core.start = function(runnab le)
    {
    Core.addEventLi stener(window, "load", runnable.init);
    };

    --
    Message posted via WebmasterKB.com


  • dhtml

    #2
    Re: Runtime Error...Can't Figure Out Why...

    LayneMitch via WebmasterKB.com wrote:
    Hello.
    >
    This is a reference file from a book I read in which the core subject is the
    use of 'event listeners'.
    >
    I'm trying to load the file in Firefox and it's giving me an error message:
    >
    Line: 5
    Char: 1
    Error: 'document' is undefined
    Code: 800A1391
    Source: Microsoft JScript Runtime Error
    >
    >
    Are you sure this Error came from Firefox?

    Comment

    • LayneMitch via WebmasterKB.com

      #3
      Re: Runtime Error...Can't Figure Out Why...

      dhtml wrote:
      >Hello.
      >>
      >[quoted text clipped - 8 lines]
      >Code: 800A1391
      >Source: Microsoft JScript Runtime Error
      >
      >Are you sure this Error came from Firefox?
      Positive.

      It's coming from firefox and IE. It's an extremely strange situation because
      the code is taken straight from the book. Also, I downloaded the code from
      the publisher's site (www.sitepoint.com), and it's giving me the same error
      for the code downloaded from the site.

      --
      Message posted via WebmasterKB.com


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Runtime Error...Can't Figure Out Why...

        LayneMitch via WebmasterKB.com wrote:
        dhtml wrote:
        >[quoted text clipped - 8 lines]
        >>Code: 800A1391
        >>Source: Microsoft JScript Runtime Error
        Are you sure this Error came from Firefox?
        >
        Positive.
        >
        It's coming from firefox and IE.
        It cannot come *from Firefox* (i.e. Gecko) because Gecko does not implement
        Microsoft JScript; it implements Netscape/Mozilla.org JavaScript instead:

        <http://PointedEars.de/es-matrix>

        This suggests instead that the cause is server-side JScript in ASP (.NET);
        HTML user agents would only display what the server has responded with (cf.
        "404 File Not Found"). Very likely other browsers (like Opera) would
        display the same error message, unless you have resorted to browser sniffing
        server-side and that is what is borken here.

        Google is your friend. [psf 6.1]
        It's an extremely strange situation because the code is taken straight
        from the book. Also, I downloaded the code from the publisher's site
        (www.sitepoint.com), and it's giving me the same error for the code
        downloaded from the site.
        It would seem you lack the minimum clue for what you are doing, which does
        not bode well for your successfully implementing this code. RTFM, STFW, RTFFAQ.


        PointedEars
        --
        realism: HTML 4.01 Strict
        evangelism: XHTML 1.0 Strict
        madness: XHTML 1.1 as application/xhtml+xml
        -- Bjoern Hoehrmann

        Comment

        • LayneMitch via WebmasterKB.com

          #5
          Re: Runtime Error...Can't Figure Out Why...

          Thomas 'PointedEars' Lahn wrote:
          >It cannot come *from Firefox* (i.e. Gecko) because Gecko does not implement
          >Microsoft JScript; it implements Netscape/Mozilla.org JavaScript instead:
          >It would seem you lack the minimum clue for what you are doing, which does
          >not bode well for your successfully implementing this code. RTFM, STFW, RTFFAQ.
          >
          And you are right to a certain extent. I am an amateur at coding. I expected
          the js files to automatically open with no complications. I have researched a
          little (yahoo instead of google), and found that this error isn't being
          caused by firefox or IE...it's a Windows problem. If you have any further
          suggestions on how to troubleshoot this, it would be much appreciated.

          --
          Message posted via WebmasterKB.com


          Comment

          • Doug Miller

            #6
            Re: Runtime Error...Can't Figure Out Why...

            In article <8870dad7cf8bb@ uwe>, "LayneMitch via WebmasterKB.com " <u39402@uwewrot e:
            >dhtml wrote:
            >>Hello.
            >>>
            >>[quoted text clipped - 8 lines]
            >>Code: 800A1391
            >>Source: Microsoft JScript Runtime Error
            >>
            >>Are you sure this Error came from Firefox?
            >
            >Positive.
            Impossible.

            --
            Regards,
            Doug Miller (alphageek-at-milmac-dot-com)

            Join the UseNet Improvement Project: killfile Google Groups.
            Debet đang ngày càng thu hút sự chú ý của người chơi cá cược trực tuyến tại Việt Nam nhờ vào các dịch vụ đa dạng và chất lượng cao. Với nhiều loại hình cá


            Get a copy of my NEW AND IMPROVED TrollFilter for NewsProxy/Nfilter
            by sending email to autoresponder at filterinfo-at-milmac-dot-com
            You must use your REAL email address to get a response.

            Download Nfilter at http://www.milmac.com/np-120.exe

            Comment

            • LayneMitch via WebmasterKB.com

              #7
              Re: Runtime Error...Can't Figure Out Why...

              Doug Miller wrote:
              >>>Hello.
              >>>>
              >[quoted text clipped - 5 lines]
              >>
              >>Positive.
              >
              >Impossible.
              >
              I think that if you would read the last post, you can see that I understand
              that this isn't Firefox or IE issue.

              --
              Message posted via WebmasterKB.com


              Comment

              • David Mark

                #8
                Re: Runtime Error...Can't Figure Out Why...

                On Aug 10, 3:03 pm, "LayneMitch via WebmasterKB.com " <u39402@uwe>
                wrote:
                Doug Miller wrote:
                >>Hello.
                >
                [quoted text clipped - 5 lines]
                >
                >Positive.
                >
                Impossible.
                >
                I think that if you would read the last post, you can see that I understand
                that this isn't Firefox or IE issue.
                I read all of your posts in this thread. You don't understand
                anything. It sounds to me like you are downloading the file and
                opening it with the shell (of course document is undefined!)

                Comment

                • LayneMitch via WebmasterKB.com

                  #9
                  Re: Runtime Error...Can't Figure Out Why...

                  David Mark wrote:
                  >I read all of your posts in this thread. You don't understand
                  >anything. It sounds to me like you are downloading the file and
                  >opening it with the shell (of course document is undefined!)
                  Okay...

                  no...I'm not 100% efficient on the use of JavaScript reference files. I'm 5
                  mths into the language. However, I do know how to write JavaScript code. I've
                  just completed my reading material and I'm ready to begin practicing a list
                  of programming examples I've come up with for myself. The problem I'm having
                  is the setup.

                  I saved the .js file to my hard-drive. I worked on one of the problems I have
                  and referenced the .js file. I then save the script as a .html, clicked on it
                  and nothing happened. I then tried to see if there was something wrong with
                  the .js file itself by using Firefox Debugger. This is when I received the
                  error, and thus thought that this is the reason why my script isn't running.

                  You're saying I'm "opening it with the shell" what does that mean and what
                  significance does it have toward this process?

                  Here is my small program:

                  <html><head><ti tle>Prob.1</title>
                  <script type="text/javascript" src="C:/typedcore.js"></script>
                  <script type="text/javascript">

                  var Nameprompt=
                  {
                  init:function()
                  {
                  var name=prompt("Wh at's your name," "");
                  Nameprompt.disp lay(name);
                  },

                  display:functio n(this)
                  {
                  document.write( "Welcome"+this+ "to the wonders of JavaScript");
                  }
                  };


                  Core.start(Name prompt)
                  </script>
                  </head>
                  <body></body>
                  </html>

                  --
                  Message posted via http://www.webmasterkb.com

                  Comment

                  • David Mark

                    #10
                    Re: Runtime Error...Can't Figure Out Why...

                    On Aug 10, 3:40 pm, "LayneMitch via WebmasterKB.com " <u39402@uwe>
                    wrote:
                    David Mark wrote:
                    I read all of your posts in this thread.  You don't understand
                    anything.  It sounds to me like you are downloading the file and
                    opening it with the shell (of course document is undefined!)
                    >
                    Okay...
                    >
                    [snip]
                    I saved the .js file to my hard-drive. I worked on one of the problems I have
                    and referenced the .js file. I then save the script as a .html, clicked on it
                    Saved the script as HTML?
                    and nothing happened. I then tried to see if there was something wrong with
                    the .js file itself by using Firefox Debugger. This is when I received the
                    error, and thus thought that this is the reason why my script isn't running.
                    >
                    You're saying I'm "opening it with the shell" what does that mean and what
                    significance does it have toward this process?
                    >
                    Here is my small program:
                    >
                    <html><head><ti tle>Prob.1</title>
                    <script type="text/javascript" src="C:/typedcore.js"></script>
                    That isn't a correct file URI. Why not place the JS file in the same
                    folder as this document and use "typedcore. js" for the src attribute?
                    <script type="text/javascript">
                    >
                    var Nameprompt=
                     {
                       init:function()
                       {
                         var name=prompt("Wh at's your name," "");
                         Nameprompt.disp lay(name);
                       },
                    >
                       display:functio n(this)
                       {
                        document.write( "Welcome"+this+ "to the wonders of JavaScript");
                       }
                     };
                    >
                    Core.start(Name prompt)
                    </script>
                    </head>
                    <body></body>
                    </html>
                    >
                    --
                    Message posted viahttp://www.webmasterkb .com

                    Comment

                    • LayneMitch via WebmasterKB.com

                      #11
                      Re: Runtime Error...Can't Figure Out Why...

                      David Mark wrote:
                      >I saved the .js file to my hard-drive. I worked on one of the problems I have
                      >and referenced the .js file. I then save the script as a .html, clicked on it
                      >
                      >Saved the script as HTML?
                      When I write JS code, to run the file what else should I save it as?
                      >That isn't a correct file URI. Why not place the JS file in the same
                      >folder as this document and use "typedcore. js" for the src attribute?
                      I tried that and it still didn't work for the moment, but I'll play around
                      with it and figure it out.
                      Thanks.

                      --
                      Message posted via WebmasterKB.com


                      Comment

                      • David Mark

                        #12
                        Re: Runtime Error...Can't Figure Out Why...

                        On Aug 10, 6:27 pm, "LayneMitch via WebmasterKB.com " <u39402@uwe>
                        wrote:
                        David Mark wrote:
                        I saved the .js file to my hard-drive. I worked on one of the problemsI have
                        and referenced the .js file. I then save the script as a .html, clicked on it
                        >
                        Saved the script as HTML?
                        >
                        When I write JS code, to run the file what else should I save it as?
                        JS?
                        >
                        That isn't a correct file URI.  Why not place the JS file in the same
                        folder as this document and use "typedcore. js" for the src attribute?
                        >
                        I tried that and it still didn't work for the moment, but I'll play around
                        with it and figure it out.
                        If you need to figure that out, you should first concentrate on
                        learning HTML.

                        Comment

                        Working...