Javascript and Windows

I noticed that if I have a .js file in Windows browser (not Internet Explorer, I mean the folder explorer ...), I can actually click on it and it will execute, giving error messages like , window object undefined. "Is there more information about the environment in which the .js script is running and the objects available?

+4
source share
5 answers

Windows Script Host provides a fairly rich environment that allows you to do many interesting things - only yesterday I used it to create a tool that analyzes a directory full of XML files that reference various resources, such as images and other XML files, and create an XML manifest in predefined pattern.

You should not spend time getting used to creating .wsf (which use XML-based syntax ), and not just .js (JScript) or .vbs (VBScript) files - .wsf provide much finer control over modules and allow better to document documents and explanations of use, and also allow you to compile scripts written in several different languages, which is convenient if you find VBScript that does 40% of what you need and do not want to use 60% of it, which you write in JScript.

+3
source

Take a look at Windows Hosting Scripting Host Docs (JScript).

+7
source

The Windows® Scripting Guide provides technical resources, information, and source code to help you automate your Windows® operating system using Windows® Script Host (WSH) and the VBScript and JScript scripting languages.

There is a lot of information about him to get you started. There are many things you can do with this. I use VBScript, which does window processing like on Linux ( alt + Drag moves the window) with a few lines of code.

You can access many system connections, including the file system. You can use any language registered with the Windows Script Host , by default, VBScript and JScript.

+1
source

You can run JScript (.js) and VBScript (.vbs) scripts directly in windows.

As you have a Javascript file designed to run on a web page, the environment it expects is different. The window and document objects are only available in the browser, so they do not work when running the script outside the browser.

The objects you have are ActiveX objects registered on the computer, for example, the Scripting.FileSystemObject object, which you can use to access the file system.

0
source

JavaScript can be executed from the command line of any operating system if you have access to a JavaScript interpreter that can be launched from the command line. Two common command-line JavaScript interpreters are Rhino from Mozilla, which requires Java and the Windows Script Helper, which can run natively in Windows.

0
source

All Articles