By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.addEventListener)
{
Core.addEventListener = function(target, type, listener)
{
target.addEventListener (type, listener, false);
};
Core.removeEventListener = function(target, type, listener)
{
target.removeEventListener(type, listener, false);
};

Core.preventDefault = function(event)
{
event.preventDefault();
};

Core.stopPropagation = function(event)
{
event.stopPropagation();
};
}

// Internet Explorer Events model

else if (document.attachEvent)
{
Core.addEventListener = function(target, type, listener)
{
// prevent adding the same listener twice, since DOM 2

// Events ignores duplicates like this

if (Core._findListener(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.prototype.call)
{
listener.call(target, event);
}

else
{
target._currentListener = listener;
target._currentListener(event)
target._currentListener = null;
}
};
// add listener2 using IE's attachEvent method
target.attachEvent("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._listenerCounter++;

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

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

// store this listener's ID in target

if (!target._listeners) target._listeners = [];
target._listeners[target._listeners.length] = listenerId;

// set up Core._removeAllListeners to clean up all

// listeners on unload

if (!targetWindow._unloadListenerAdded)
{
targetWindow._unloadListenerAdded = true;
targetWindow.attachEvent(
"onunload", Core._removeAllListeners);
}
};
Core.removeEventListener = function(target, type, listener)
{
// find out if the listener was actually added to target

var listenerIndex = Core._findListener(
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._listeners[listenerIndex];
var listenerRecord =
targetWindow._allListeners[listenerId];

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

target.detachEvent("on" + type, listenerRecord.listener2);
target._listeners.splice(listenerIndex, 1);

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

delete targetWindow._allListeners[listenerId];

};

Core.preventDefault = function(event)
{
event.returnValue = false;
};

Core.stopPropagation = function(event)
{
event.cancelBubble = true;
};

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

var listeners = target._listeners;
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.length - 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._allListeners[listenerId];

// compare type and listener with the retrieved record

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

Core._removeAllListeners = function()
{
var targetWindow = this;

for (id in targetWindow._allListeners)
{
var listenerRecord = targetWindow._allListeners[id];
listenerRecord.target.detachEvent(
"on" + listenerRecord.type, listenerRecord.listener2);
delete targetWindow._allListeners[id];
}
};

Core._listenerCounter = 0;

}
Core.addClass = function(target, theClass)
{
if (!Core.hasClass(target, theClass))
{
if (target.className == " ")
{
target.className = theClass;
}

else
{
target.className += " " + theClass;
}
}

};
Core.getElementsByClass = function(theClass)
{
var elementArray = [];

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

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

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

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

return matchedArray;

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

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

return false;

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

target.className = target.className.replace(pattern, "$1");
target.className = target.className.replace(/ $/, " ");
};
Core.getComputedStyle = function(element, styleProperty)
{
var computedStyle = null;

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

else
{
computedStyle =
document.defaultView.getComputedStyle(element, null);
}

return computedStyle[styleProperty];

};

Core.start = function(runnable)
{
Core.addEventListener(window, "load", runnable.init);
};

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 10 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
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?
Aug 10 '08 #2

P: n/a
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
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 10 '08 #3

P: n/a
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
Aug 10 '08 #4

P: n/a
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
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 10 '08 #5

P: n/a
In article <8870dad7cf8bb@uwe>, "LayneMitch via WebmasterKB.com" <u39402@uwewrote:
>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.
http://www.improve-usenet.org

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

Aug 10 '08 #6

P: n/a
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
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 10 '08 #7

P: n/a
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!)
Aug 10 '08 #8

P: n/a
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><title>Prob.1</title>
<script type="text/javascript" src="C:/typedcore.js"></script>
<script type="text/javascript">

var Nameprompt=
{
init:function()
{
var name=prompt("What's your name," "");
Nameprompt.display(name);
},

display:function(this)
{
document.write("Welcome"+this+"to the wonders of JavaScript");
}
};
Core.start(Nameprompt)
</script>
</head>
<body></body>
</html>

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

Aug 10 '08 #9

P: n/a
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><title>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("What's your name," "");
* * *Nameprompt.display(name);
* *},

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

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

--
Message posted viahttp://www.webmasterkb.com
Aug 10 '08 #10

P: n/a
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
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 10 '08 #11

P: n/a
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.
Aug 10 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.