Есть ли способ вызвать несколько HTA-APP в одном пакете?
У меня есть несколько страниц HTA, которые я хочу вызывать в разных местах из пакета.
Например:
<!-- :: Batch section
@echo off
setlocal enableextensions disabledelayedexpansion
for /F "tokens=1,2 delims=|" %%a in ('mshta.exe "%~F0"') do (
set "field1=%%a"
set "field2=%%b"
)
echo %field1%
echo %field2%
set var=hallo
for /F "delims = " %%a in ('mshta.exe "%~F0" %var%') do set "HtaResult=%%a"
echo Result = %HtaResult%
echo End of HTA window
pause
goto :EOF
Проблема в том, что я хочу вызвать оба HTA в пакете. На данный момент я всегда звоню только на первый АТП. Есть ли возможность?





По схеме вашего предыдущего вопроса
<!-- :: Batch section
@echo off
setlocal enableextensions disabledelayedexpansion
rem use command line arguments to tell the hta what to do
rem Defined which tokens we need and the delimiter between them
for /F "tokens=1,2 delims=|" %%a in ('mshta.exe "%~F0" test1') do (
set "field1=%%a"
set "field2=%%b"
)
echo End of HTA 1 window, reply: "%field1%" "%field2%"
for /F "tokens=1" %%a in ('mshta.exe "%~F0" test2') do (
set "field1=%%a"
)
echo End of HTA 2 window, reply: "%field1%"
pause
goto :EOF
-->
<HTML>
<HEAD>
<!-- you will need to give an ID to the HTA -->
<HTA:APPLICATION SCROLL = "no" SYSMENU = "no" ID = "thisHTAID" >
<TITLE>HTA Buttons</TITLE>
<SCRIPT language = "JavaScript">
window.resizeTo(374,400);
// function handling test1 hta output
function myFunction() {
new ActiveXObject("Scripting.FileSystemObject")
.GetStandardStream(1)
.WriteLine(
[ // Array of elements to return joined with the delimiter
document.getElementById("myText").value
, document.getElementById("myText2").value
].join('|')
);
window.close();
};
// functio handling test2 hta output
function myButton( selected ){
new ActiveXObject("Scripting.FileSystemObject")
.GetStandardStream(1)
.WriteLine( selected );
window.close()
};
// on window load select what div to show depending on command line
window.onload = function(){
var commandLine = thisHTAID.commandLine;
commandLine = commandLine.substr(
self.location.pathname.length
+ ( commandLine.substr(0,1) === '"' ? 2 : 0 )
).replace(/^\s+/g,'');
document.getElementById( commandLine ).style.display='block';
};
</SCRIPT>
</HEAD>
<BODY>
<!-- hide hta screens inside div tags -->
<div id = "test1" style='display:none'>
<h3>A demonstration of how to access a Text Field</h3>
<input type = "text" id = "myText" value = "0123">
<input type = "text" id = "myText2" value = "4567">
<p>Click the "Login" button to get the text in the text field.</p>
<button onclick = "myFunction()">Login</button>
</div>
<div id = "test2" style='display:none'>
<h3>Just another demostration</h3>
<button onclick = "myButton(1)">button1</button>
<button onclick = "myButton(2)">button2</button>
</div>
</BODY>
</HTML>
Основная идея, изложенная в комментариях к коду, состоит в том, чтобы определить, какой слой отображать, в зависимости от аргументов командной строки, заданных при вызове HTA.
И как бы выглядела эта часть, если бы я хотел передать несколько переменных из цикла FOR в JScript? Спасибо
@TheDude, вы не должны вносить изменения в элементы на странице, пока не завершится процесс загрузки, поэтому код для отображения соответствующего слоя выполняется при запуске события загрузки. Посмотрите, как слой передается из команды FOR в свойство commandLine, и измените его, чтобы анализировать больше аргументов.
Спасибо за ответ, думаю так я смогу решить свою проблему! Я не совсем понял часть с "window.onload=функция()", можете мне объяснить поточнее? Как мне настроить это, когда у меня 3 объявления? Заранее спасибо за помощь!