Can I run JavaScript without a browser?

R

RC

I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.
 
W

Webrickco

I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.

Well, it's a good question. However i think the language itself is
bind to the browser. How would it understand
"document.getElementById..." for example if not attached to a browser?
 
R

RC

Webrickco said:
Well, it's a good question. However i think the language itself is
bind to the browser. How would it understand
"document.getElementById..." for example if not attached to a browser?

For example, when I test my Perl CGI script.
Instead click the Submit button from the HTML file in
a browser. I can test my Perl script file from
command line like

perl myscript.pl

Or add line #!/usr/bin/perl -w at the top of file
Then just execute it.

Similar for php

I am wonder is there javascript shell allows me execute
from command line like

javascript myjavascript.js
or
javascript myfile.html
 
F

filippo pacini

RC said:
I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.

Hi,
take also a look at spidermonkey, The mozilla implementation of javascript.

http://www.mozilla.org/js/spidermonkey/

On ubuntu you can install it with:
apt-get install spidermonkey-bin

cheers,
 
D

Dr J R Stockton

Wed said:
I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.


Select Windows XP Start, Help and Support, then search for "cscript" and
"wscript", or search for "javascript" and read "Windows Script Host
overview".

Note
(0) Details may depend on system
(1) MS use the term JScript

<FAQENTRY> The FAQ should say a little more about JScript & WSH; add to
2.7 that JScript can be run from Windows command-line or GUI without
using a browser, and then has API access to the local system.

It's a good idea to write the newsgroup c.l.j and its FAQ. See below.
 
J

jcb

Well, it's a good question. However i think the language itself is
bind to the browser. How would it understand
"document.getElementById..." for example if not attached to a browser?

Thats part of DOM, a library, and not strictly part of javascript itself.

J.
 
J

jcb

I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.

If your running you can install spidermonkey librariy (libjs) with

sudo yum install js

js is the javascript interpreter

J.
 
J

jcb

If your running you can install spidermonkey librariy (libjs) with

sudo yum install js

js is the javascript interpreter

J.


Sorry - that should be if you are running the fedora linux distribution.

J.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Dr J R Stockton said the following on 7/26/2007 8:32 AM:



comp.lang.javascript is dedicated to client side scripting on the web.

No, it is not so dedicated. That is merely the default assumption, when
not otherwise specified. Read FAQ section 2.2 para 1.

The aspect of covering Windows based scripting has been discussed
before and this isn't the group for it.

But I am not suggesting "covering" it; merely that the FAQ should very
briefly indicate the other things which can be done with ECMAScript.
When people ask about it they either get answered or pointed to a
group dedicated to WScript/Cscript and as such it shouldn't have
anything in the FAQ other than a "For Windows based scripting newsgroup
...... is the place to ask".

But the FAQ is an ideal place to do that redirection, and to present the
actual value of .......'.

When are you going to deliver a new version of the FAQ? You have
achieved nothing useful for over four months now.

It's a good idea to read the newsgroup c.l.j and write its FAQ. See below.
 
P

Peter Michaux

I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.

If you are trying to test browser scripts on the server you might be
interested in what John Resig has done

http://ejohn.org/blog/bringing-the-browser-to-the-server/

and why this is a bad idea. Almost all big chunks of code has bugs so
writing a buggy simulation of buggy browsers wouldn't be very
productive to test browser bugs in relation to your scripts. I believe
the approach of Selenium is better for automated testing

http://www.openqa.org/

Although I'm not so keen on mini meta-languages like Selenese and the
software requires the Prototype library.

----------

If you are just interested in JavaScript on the server-side for
general-purpose scripting and other tasks for which folks use Perl/
Python/Ruby, then Spidermonkey and Rhino are the projects to check
out. I've been doing quite a bit of C programming lately to extend
Spidermonkey and it is infinitely flexible.

Peter
 
T

Thomas 'PointedEars' Lahn

Randy said:
Dr J R Stockton said the following on 7/26/2007 8:32 AM:

comp.lang.javascript is dedicated to client side scripting on the web.

While most of the postings fall into that category, I don't think in
such absolute terms. For me, this is the place where to discuss the
language *and* its applications.


PointedEars
 
R

RMZ

I wrote many JavaScripts, they can only run
in a browser (Netscape, IE, Firefox, etc.)
I am wonder how can I run the JavaScript
in the command line (UNIX/LINUX, Windows)?
Similar we can run Perl, PHP, Python, Visual Base, .Net,
etc. in command line, Desktop.

Yes you can. On the Windows platform see:
http://www.microsoft.com/technet/scriptcenter/guide/sas_roa_overview.mspx?mfr=true

Most examples are in VBScript, but the Windows Scripting Host also
supports ECMAScript/JavaScript.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top