質問

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

Second window is executed by:

Sub Settings()
  Set objShell = CreateObject("WScript.Shell")
  objShell.Run "Launcher-Settings.hta"
End Sub 

And the button is:

<input type="button" value="Settings" name="MSG-Button" id="LauncherSettings1" class="LauncherSetting1" onClick="Settings()" />

Both windows are close by:

<input type="button" value="<<    Close" name="CloseButton" id="CloseButton" class="CloseButton" onClick="javascript:Window.close()" />
役に立ちましたか?

解決

There's a typo in my comment, it should be "unload events are not cancelable...".

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top