JavaScript 和 Windows

发布于 2024-08-06 17:04:40 字数 144 浏览 4 评论 0原文

我注意到,如果我在 Windows 资源管理器(不是 Internet Explorer,我的意思是文件夹资源管理器...)中有一个 .js 文件,我实际上可以单击它,它将执行,给出错误消息,例如“窗口对象是不明确的”。是否有有关 .js 脚本运行环境和可用对象的更多信息?

I noticed that if I have a .js file in windows explorer (not Internet Explorer, I'm meaning the folder explorer...) I can actually click on it and it will execute, giving error messages, like say "window object is undefined". Is there more information about the environment where the .js script are run into and the objects available?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

你与清晨阳光 2024-08-13 17:04:40

查看 Windows脚本宿主文档 (JScript)。

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

趁微风不噪 2024-08-13 17:04:40

Windows 脚本宿主 提供了一个相当丰富的环境,允许它可以做各种有趣的事情 - 就在昨天,我用它创建了一个工具,可以分析充满 XML 文件的目录,这些文件引用各种资源(例如图像和其他 XML 文件),并以预定义模式生成 XML 清单。

花时间习惯创建 .wsf 文件(使用 基于 XML 的语法),而不是仅仅运行 .js (JScript) 或 .vbs (VBScript)文件 - .wsf 文件提供了对模块化的更精细的控制,并允许更好的文件内文档和使用说明,还允许组合用多种不同语言编写的脚本,如果您发现VBScript 可以完成您需要的 40% 的工作,并且不希望将其转换为与您在 JScript 中编写的 60% 的工作一起使用的麻烦。

Windows Script Host provides a reasonably rich environment allowing one to do a variety of interesting things - just yesterday I used it to create a tool that analyses a directory full of XML files which reference various resources such as images and other XML files, and produce an XML manifest in a predefined schema.

It's worth taking the time to get used to creating .wsf files (which use an XML-based syntax), rather than just running .js (JScript) or .vbs (VBScript) files - .wsf files offer much finer control over modularity and allow for better in-file documentation and usage explanations, and also allow scripts written in several different languages to be combined, which is handy if you find a VBScript that does 40% of what you need and don't want the hassle of converting it to use with the 60% you're writing in JScript.

爱你是孤单的心事 2024-08-13 17:04:40

Windows® 脚本指南提供技术资源、信息和源代码,帮助您使用 Windows® Script Host (WSH) 以及 VBScript 和 JScript 脚本语言自动化 Windows® 操作系统。

大量信息帮助您入门。您可以用它做很多事情。我正在使用 VBScript,只需几行代码就可以像在 Linux 中一样进行窗口处理(alt+Drag 移动窗口)。

您可以访问系统的许多挂钩,包括文件系统。您可以使用任何已在 Windows Script Host 注册的语言,默认情况下为 VBScript 和 JScript 。

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

There is much information out there to get you started. There are many things you can do with it. I'm using a VBScript that makes the window handling work as in Linux (alt+Drag moves a window) with jus a few lines of code.

You can access many hooks to the system, including the file system. You can use any language that has registered itself with Windows Script Host, by default, VBScript and JScript.

扛起拖把扫天下 2024-08-13 17:04:40

您可以直接在 Windows 中运行 JScript (.js) 和 VBScript(.vbs) 脚本。

由于您拥有的是一个旨在在网页中运行的 Javascript 文件,因此它期望的环境是不同的。 windowdocument 对象仅在浏览器内部可用,因此当您在浏览器外部运行脚本时它们不起作用。

您可用的对象是在计算机上注册的 ActiveX 对象,例如可用于访问文件系统的 Scripting.FileSystemObject 对象。

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

As what you have is a Javascript file intended to run in a web page, the environment that it expects is different. The window and document objects are only available inside the browser, so they don't work when you run the script outside the browser.

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

盛夏已如深秋| 2024-08-13 17:04:40

只要您有权访问可以从命令行执行的 JavaScript 解释器,就可以从任何操作系统的命令行执行 JavaScript。两种常见的命令行 JavaScript 解释器是 Mozilla 的 Rhino(需要 Java)和 Windows Script Helper(可以在 Windows 环境中本机运行)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文