Executing JavaScript without a browser?
I found this related question on the topic, but if you want direct links, here they are:
- You can install Rhino as others have pointed out. This post shows an easy way to get it up and running and how to alias a command to invoke it easily
- If you're on a Mac, you can use JavaScriptCore, which invokes WebKit's JavaScript engine. Here's a post on it
- You can use Chome/Google's V8 interpreter as well. Here are instructions
- The JavaScript as OSA is interesting because it lets you (AFAIK) interact with scriptable OS X apps as though you were in AppleScript (without the terrible syntax)
I'm surprised node.js doesn't come with a shell, but I guess it's really more like an epoll/selector-based callback/event-oriented webserver, so perhaps it doesn't need the full JS feature set, but I'm not too familiar with its inner workings.
Since you seem interested in node.js and since it's based on V8, it might be best to follow those instructions on getting a V8 environment set up so you can have a consistent basis for your JavaScript programming (I should hope JSC and V8 are mostly the same, but I'm not sure).
Execute Javascript without using a browser
You cannot execute the javascript on a webpage without a browser. The browser is precisely the software that renders a webpage and lets code interact with it. This is not something ASIHTTPRequest
will ever be able to do.
However, you can use PhantomJS which is basically a headless and scriptable browser. But packaging that within your app may be tricky.
Or possibly, to stay in Cocoa realm, you could load a WebView up with the page that you want, and never display it on screen. You can then execute javascript in that WebView to return data.
However, this seems like a bad idea. Downloading a page, all it's assets, parsing and rendering it, then executing javascript is a slow and memory intensive operation. It will be so much cleaner if you can make your server just give you the data you want without having to run any complex client side scripts.
It's hard to advise more without knowing what you are trying to do, but do yourself a favor and rethink your strategy here.
How can I run JavaScript in Notepad++ without using HTML?
To run JavaScript you need a runtime environment. This is generally provided by your browser.
You can use Node, to run javascript without browsers.
Working javascript without browser
JavaScript can be run by any interpreter for JavaScript such as the windows script host or node.js runtime environment. But those are different environments with different global scope. For example, using windows, you can save a .js-file from a webapp to the desktop and try to run it. The windows script host will run it but likely fail because it does not have the same objects in its global scope that browsers use.
A script executed inside a browser will always terminate with the browser as the browser is the process executing the script. The script itself isn't in a native executable format and, thus, can't be run by the OS itself instead it requires the browser to interpret the code.
Related Topics
How to Persist a Es6 Map in Localstorage (Or Elsewhere)
Jquery .Find() Doesn't Return Data in Ie But Does in Firefox and Chrome
Ipad/iPhone Browser Crashing When Loading Images in JavaScript
What Is Array Literal Notation in JavaScript and When Should You Use It
Convert Nan to 0 in JavaScript
Calculating Jday(Julian Day) in JavaScript
Pass JavaScript Variable to Flask Url_For
How to Add a Class to a Dom Element in JavaScript
Should I Refrain from Handling Promise Rejection Asynchronously
Detect When User Accepts to Download a File
How to Get the Exact Local Time of Client
Detect If Browser Tab Is Active or User Has Switched Away
Referenceerror: Document Is Not Defined (In Plain JavaScript)
What Is the $$ (Double Dollar Sign) Used for in Angular
Fetching Values from Email in Protractor Test Case