是否可以使用不带window.close()的javascript发送HTAREPLY [英] Is it possible to send HTAREPLY with javascript without window.close()
问题描述
我正在构建一个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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!