windows 如何在没有浏览器的情况下显示弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3106806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show a popup without a browser
提问by Luke101
I need an "alert" type feature to troubleshoot an error. I am not using a browser and using javascript as windows administaration purposes. So is their a way to view a varibales value if I am not using a browser?
我需要一个“警报”类型的功能来解决错误。我没有使用浏览器,而是使用 javascript 作为 Windows 管理目的。那么,如果我不使用浏览器,他们是否可以查看变量值?
回答by Bruno DeGoia
JScriptis a scripting language based on the ECMAScriptstandard.
JScript是一种基于ECMAScript标准的脚本语言。
JScriptis implemented as a Windows Scriptengine. This means that it can be plugged into any application that supports the Windows Scripthost, such as Internet Explorer, Active Server Pages, etc. It also means that any application supporting Windows Script can use multiple languages — JScript, VBScript, Perl, and others.
JScript是作为Windows 脚本引擎实现的。这意味着它可以插入任何支持Windows 脚本宿主的应用程序,例如 Internet Explorer、Active Server Pages 等。这也意味着任何支持 Windows 脚本的应用程序都可以使用多种语言——JScript、VBScript、Perl 和其他。
For reasons that I am not sure about, but I believe it to be related to the fact the the DOMis not available outside the browser, the alertfunction is also not available outside the browser. In order to popup a dialog box to the user in this case you can use the following code:
由于我不确定的原因,但我认为这与DOM在浏览器之外不可用的事实有关,警报功能在浏览器之外也不可用。为了在这种情况下向用户弹出一个对话框,您可以使用以下代码:
WScript.Echo('The quick brown fox jumped over the lazy dog');
回答by glenn Hymanman
If you want a windows GUI popup, then:
如果你想要一个 Windows GUI 弹出窗口,那么:
var timeout = 0;
var buttons = 0; // OK
var icon = 48; // Exclamation
var shell = new ActiveXObject("WScript.Shell");
shell.Popup("text ...", timeout, "window title", buttons + icon);
and run your jscript program with the wscript
command.
并使用wscript
命令运行您的 jscript 程序。
- Microsoft JScript language reference.
- Popup documentation.
- Microsoft JScript 语言参考。
- 弹出文档。
回答by Alan
On windows, you can use Windows Script Host to execute your javascript. It has a built in ability to do output, using Echo. There are some nuances though, since WSH uses jscript, not javascript, though the languages are similar.
在 Windows 上,您可以使用 Windows Script Host 来执行您的 javascript。它具有使用Echo进行输出的内置功能。虽然有一些细微差别,因为 WSH 使用 jscript,而不是 javascript,尽管语言相似。
回答by Jeff
Look at HTA files. These file types allow you to run typical HTML/VBScript/JS code without the need for a browser specifically. Just rename your HTML file to an HTA extension and run it. IT will show your "page" and execute any JS necessary. This type of file will give you access to other WScript functions as well like creating Files or accessing AD if required.
查看 HTA 文件。这些文件类型允许您运行典型的 HTML/VBScript/JS 代码,而无需专门的浏览器。只需将您的 HTML 文件重命名为 HTA 扩展名并运行它。它会显示您的“页面”并执行任何必要的 JS。这种类型的文件将使您能够访问其他 WScript 功能,以及在需要时创建文件或访问 AD。
回答by user347594
No with javascript. You can, using Visual Basic Script and MsgBox function. No need to install anything.
没有 javascript。您可以使用 Visual Basic Script 和 MsgBox 函数。无需安装任何东西。
'In Hello.vbs. Comments starts with '
MsgBox "Hello there"
回答by Shane Reustle
You can create a simple file that will alert text that is passed to it, for example in python. I don't think there is any way to do this in Javascript though without a browser.
您可以创建一个简单的文件来提醒传递给它的文本,例如在 python 中。尽管没有浏览器,我认为在 Javascript 中没有任何方法可以做到这一点。
回答by Zev Spitz
A summary of the differences between WScript.Echo
and WshShell.Popup
:
WScript.Echo
和之间的区别总结WshShell.Popup
:
- Windows scripts (vbs, js, wsf etc.) can be run under one of two hosts: cscript.exe(command-line), and wscript.exe(graphical). Under cscript,
WScript.Echo
will produce a line of text in the console window.WshShell.Popup
will always produce a message window, even under cscript. WshShell.Popup
lets you specify the buttons, title and icon type, like the VB/VBSMessageBox
function. It also lets you specify how long the message should remain open.WScript.Echo
lets you pass multiple string arguments to output, and will print them separated with spaces.
- Windows 脚本(vbs、js、wsf 等)可以在以下两个主机之一下运行:cscript.exe(命令行)和wscript.exe(图形)。在 cscript 下,
WScript.Echo
会在控制台窗口中产生一行文本。WshShell.Popup
总是会产生一个消息窗口,即使在 cscript 下也是如此。 WshShell.Popup
允许您指定按钮、标题和图标类型,如 VB/VBSMessageBox
功能。它还允许您指定消息应保持打开状态的时间。WScript.Echo
允许您将多个字符串参数传递给输出,并将打印它们以空格分隔。