Is it possible to send HTAREPLY with javascript without window.close()

白昼怎懂夜的黑 提交于 2019-12-06 06:11:34

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...

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...

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>

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...

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