如何使HTA窗口依赖于另一个窗口? [英] How can i make an HTA window dependent on another?
问题描述
我需要使一个.hta
窗口依赖于另一个.hta
窗口.因此,基本上没有窗口B首先关闭就无法关闭窗口A.我将两个窗口彼此相邻,单击设置时它们就充当一个窗口(它基本上显示第一个窗口的弹出窗口或扩展名,该窗口具有该应用程序的选项).
I need to make an .hta
window dependent on the other .hta
window. So, basically window A cannot be closed without window B being close first. I have the two window right next to each other and they act as one window when settings is click (it basically displays a popout or extension of the first window that has options for the application).
第二个窗口由执行:
Sub Settings()
Set objShell = CreateObject("WScript.Shell")
objShell.Run "Launcher-Settings.hta"
End Sub
按钮是:
<input type="button" value="Settings" name="MSG-Button" id="LauncherSettings1" class="LauncherSetting1" onClick="Settings()" />
两个窗口都在附近:
<input type="button" value="<< Close" name="CloseButton" id="CloseButton" class="CloseButton" onClick="javascript:Window.close()" />
推荐答案
我的注释中有错字,应该是"unload
事件不可取消...".
There's a typo in my comment, it should be "unload
events are not cancelable...".
您可以使用WMI强制在关闭A之前关闭窗口B,如下所示:
You can force window B to be closed just before closing A using WMI, something like this:
top.onbeforeunload = function () {
var wmiLocator = new ActiveXObject('WbemScripting.SWbemLocator'),
wmiService = wmiLocator.ConnectServer('.', 'root\\CIMV2'),
htaProcesses = new Enumerator(wmiService.ExecQuery("Select * from Win32_Process Where name = 'mshta.exe'")),
htas = [], n;
while (!htaProcesses.atEnd()) {
if (htaProcesses.item().CommandLine.indexOf('Launcher-Settings.hta') > -1) {
htas.push(htaProcesses.item());
}
htaProcesses.moveNext();
}
for (n = 0; n < htas.length; n++) {
htas[n].Terminate();
}
return;
}
这篇关于如何使HTA窗口依赖于另一个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!