I'd like to add one thing to Scott's very informative reply...

You may wonder, "But I wasn't trying to run the script from the Windows
command prompt! I pasted it into the IE address bar and that's when I was
prompted to open or save it."

Like the doctor said, "If that hurts, don't do it."

The behavior you saw is what IE does with *any* .js file URL you enter into
the address bar. It doesn't have anything to do specifically with jQuery,
and it's not the way jQuery or similar scripts would normally be loaded.

The normal use for a script like jQuery is to include its URL in a <script>
tag in an HTML document. When you open that HTML document in a browser, it
loads the JavaScript code from the .js file within the normal context of a
web page.

It *is* possible to run a .js file as if it were a Windows application -
either from the command line or with the accidental method you stumbled
across. But that doesn't run the JavaScript code in a browser environment.
It runs it under the Windows Scripting Host, which doesn't have browser
objects like 'document', but does have a variety of Windows-specific
objects. So this requires JavaScript code that was written specifically to
run under Windows Scripting Host, not a browser-oriented script like jQuery.

-Mike

On Mon, Dec 7, 2009 at 10:15 AM, Scott Sauyet <scott.sau...@gmail.com>wrote:

> On Dec 7, 11:49 am, Firefox <barrie.wh...@gmail.com> wrote:
> > I have recently been tasked with making sure the following script
> > works with our environment.
> >
> > http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js [ ... ]
>
> That script is the latest release of the jQuery library.
>
> It doesn't do any work you care about by itself.  It needs to be
> included in a web page to do anything useful. [1]
>
> > However when running under IE (any version) I first get asked if I
> > want to open/save/cancel the file, when choosing open I get the
> > following error [ ... ]
> >
> > Error: 'document' is undefined
>
> This is not a script that can simply run from the command line.
> Windows will by default try to open this up as an executable script,
> but will not supply a browser environment that includes the global
> variable "document", hence the error.
>
> You need to look at some introductory documentation to see what jQuery
> is for and how to use it.   I would suggest starting with this:
>
>    http://docs.jquery.com/How_jQuery_Works
>
> Any place in that tutorial that has a script tag with this:
>
>    src="jquery.js"
>
> you can substitute:
>
>    src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
> jquery.min.js"
>
> That should get you going.
>
> But the notion of testing whether it will "work" in your environment
> is pretty fuzzy.  jQuery is well established and works for many people
> working in the vast majority of commonly-seen browsers over a great
> many tasks, but without additional code to actually do something with
> it, it's not clear what it would meant that it works.
>
> Good luck,
>
>  -- Scott
>
> [1] This is an oversimplification, but is enough for this discussion.
>

Reply via email to