是否可以使用不带window.close()的javascript发送HTAREPLY

编程入门 行业动态 更新时间:2024-10-28 18:34:09
本文介绍了是否可以使用不带window.close()的javascript发送HTAREPLY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个HTA/Batch脚本,该脚本包括一个界面,供用户向该脚本发送htareply,该界面将向服务器发送链接以在Jenkins上执行构建脚本.一切正常,但我想知道是否可以将hta窗口保持打开状态,以便用户根据需要选择其他选项.有什么想法吗?

I am building an HTA/Batch script that includes an interface for a user to send an htareply to the batch script that will send a link to a server to execute a build script on Jenkins. Everything works great but I was wondering if I can leave the hta window open so the user can select another option if required. Any ideas?

我试图从javascript中删除window.close(),但随后它没有将htareply发送到批处理脚本.

I attempted to remove the window.close() from the javascript but then it does not send the htareply to the batch script.

<!-- :: Batch section @echo off setlocal echo Select an option: for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a" echo End of HTA window, reply: "%HTAreply%" PAUSE goto :EOF --> <HTML> <HEAD> <HTA:APPLICATION SCROLL="no" SYSMENU="no" > <TITLE>HTA Radio Buttons</TITLE> <SCRIPT language="JavaScript"> window.resizeTo(440,170); var reply = "No button selected"; function sendreply(){ var fso = new ActiveXObject("Scripting.FileSystemObject"); fso.GetStandardStream(1).WriteLine(reply); //window.close(); } </SCRIPT> </HEAD> <BODY> <p>Select an option.</p> <label><input type="radio" name="option1" onclick="reply=this.value" value="option1">Option1</label> <label><input type="radio" name="option2" onclick="reply=this.value" value="option2">Option2</label> <label><input type="radio" name="option3" onclick="reply=this.value" value="option3">Option3</label> <br><br> <button onclick="sendreply()">Submit</button> <button onclick="window.close()">Close</button> </BODY> </HTML>

我想发生的是,如果用户选择并选择并提交,则hta窗口将保持打开状态,直到他们选择关闭"为止.

What I would like to happen is if the user selects and option and submits, the hta window remains open until they select "close".

推荐答案

for /F命令的工作方式如下: first 执行嵌套命令,收集其所有输出并等待其终止; 然后开始使用收集的行在for主体中执行命令.因此,如果要同时(并行)执行,则可以不使用for /F ...

The for /F command works this way: first execute the nested command, collect all its output and wait for it to terminate; then start to execute the commands in the for body with the collected lines. For this reason, you can not use for /F if you want simultaneous (parallel) execution...

您可以使用左侧的HTA部分和右侧的Batch部分的管道.但是,当set /P命令从管道读取输入时,它表现出奇怪的行为...

You may use a pipe with the HTA part in the left side and Batch part in the right side. However, when set /P command read input from a pipe, it presents a strange behavior...

解决方案是使用辅助文件,因此将HTA部分写入其中,并从中读取Batch部分:

The solution is to use an auxiliary file, so HTA part write to it and Batch part read from it:

<!-- :: Batch section @echo off setlocal rem Initialize Batch side interface the first time if "%~1" equ "interface" goto :interface rem Empty pipe file cd . > pipeFile.txt echo Select an option: rem Start HTA-Batch interface mshta.exe "%~F0" >> pipeFile.txt | "%~F0" interface < pipeFile.txt PAUSE del pipeFile.txt goto :EOF :interface set "HTAreply=" set /P "HTAreply=" if "%HTAreply%" equ "" goto interface echo Reply: "%HTAreply%" if "%HTAreply%" neq "EOF" goto interface echo End of HTA window goto :EOF --> <HTML> <HEAD> <HTA:APPLICATION SCROLL="no" SYSMENU="no" > <TITLE>HTA Radio Buttons</TITLE> <SCRIPT language="JavaScript"> window.resizeTo(440,170); var reply = "No button selected"; var fso = new ActiveXObject("Scripting.FileSystemObject"); function sendreply(){ fso.GetStandardStream(1).WriteLine(reply); //window.close(); } </SCRIPT> </HEAD> <BODY> <p>Select an option.</p> <label><input type="radio" name="option1" onclick="reply=this.value" value="option1">Option1</label> <label><input type="radio" name="option2" onclick="reply=this.value" value="option2">Option2</label> <label><input type="radio" name="option3" onclick="reply=this.value" value="option3">Option3</label> <br><br> <button onclick="sendreply()">Submit</button> <button onclick="fso.GetStandardStream(1).WriteLine('EOF'); window.close()">Close</button> </BODY> </HTML>

在此解决方案中,HTA和批处理零件是通过管道|启动的,只是要并行运行.请记住,这两个部分之间的通信是通过pipeFile执行的.

In this solution HTA and Batch parts are started via a pipeline | just to run both in parallel; remember that the communication between the two parts is performed via the pipeFile...

更多推荐

是否可以使用不带window.close()的javascript发送HTAREPLY

本文发布于:2023-10-19 11:19:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507334.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   不带   window   HTAREPLY   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!