Prompt dialog in WSH using JScript?

时光怂恿深爱的人放手 提交于 2019-12-22 03:09:53

问题


How to open a prompt dialog box in WSH usig JScript??

The only pop-up dialog I've found in the doc is the WshShell.Popup() method. But I need a way to request the user to enter a string, like the window.prompt() method in DOM.

Thanks.


回答1:


I think the WScript object does not provide such a method however you can show an input box from vbscript running on WSH. So here is one possible solution which lets you call that VB function from within JS! Please note the file extension for the following code fragment ".wsf".

<!-- Test.wsf -->
<job id="InputBoxInJS">
   <script language="VBScript">
      Function VBInputBox(promptText)
        VBInputBox = InputBox(promptText)
      End Function
   </script>

   <script language="JScript">
      WScript.Echo("Hello from JScript")
      var x = VBInputBox("Enter text")
      WScript.Echo(x)
   </script>
</job>



回答2:


I know this question has been answered, but I wouldn't want to use the .wsf stuff and I also wouldn't want the overhead of loading internet explorer (as I've seen other solutions do). I found this solution using Google that I think is the most elegant:

http://with-love-from-siberia.blogspot.com/2009/12/msgbox-inputbox-in-jscript.html

The key is using the ActiveXObject "ScriptControl", setting the language to VBScript and then using the ScriptObject.eval() function. The example on the site stands on its own.

EDIT: For those encountering an error with 64 bit or line feed, etc., there's this improved version with instructions on how to run it (on systems like Win7 x64) here.



来源:https://stackoverflow.com/questions/532138/prompt-dialog-in-wsh-using-jscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!