在所有窗口上方运行hta

时间:2021-06-18 07:27:37

I have an HTML application that I want to stay on top of all windows (that is, if another window is opened/switched to, I want this one to cover it). JavaScript solutions don't work in Windows 7/IE9 Mode (not sure which is holding it back, can't change either), and VBScript solutions seem to either fail outright or depend on outside components. I can't use modal dialogs either because I need this to be on top of ALL other windows, not just its parent.

我有一个HTML应用程序,我想要保持在所有窗口之上(也就是说,如果打开/切换到另一个窗口,我希望这个窗口覆盖它)。 JavaScript解决方案在Windows 7 / IE9模式下不起作用(不确定哪个会阻止它,也不能改变),并且VBScript解决方案似乎要么彻底失败,要么依赖于外部组件。我不能使用模态对话框,因为我需要它在所有其他窗口之上,而不仅仅是它的父窗口。

And don't mark this as a duplicate of https://*.com/questions/24539339/how-to-open-a-hta-window-on-top-of-all-other-windows because that (unfortunately still unanswered) question refers to opening above other windows, not maintaining stack position.

并且不要将此标记为https://*.com/questions/24539339/how-to-open-a-hta-window-on-top-of-all-other-windows的副本,因为那(不幸的是仍然未答复的)问题是指在其他窗户上方打开,而不是维持堆叠位置。

What I have tried:

我试过的:

  • Three of the suggestions outlined here.
  • 这里概述了三个建议。
  • The JavaScript solution here.
  • 这里的JavaScript解决方案。
  • The little VBScript here.
  • 这里的小VBScript。
  • Probably a dozen or more subtle variations on each of the above.
  • 可能上面的每一个都有十几个或更多微妙的变化。

Keep in mind that I can't download an extra component (no autoit or nircmd). It should all be integrated into a single file, preferably an hta, but not a zip.

请记住,我无法下载额外的组件(没有autoit或nircmd)。它应该全部集成到一个文件中,最好是一个hta,而不是一个zip。

My Solution

Only very slightly adapted from Teemu's solution, mainly for portability (just in case).

只是略微改编自Teemu的解决方案,主要是为了便携性(以防万一)。

<script language="javascript">
    var locationstore = location.href
    [...]
    window.onload = function () {
        var shell = new ActiveXObject('WScript.Shell'),
            forceModal = function (e) {
                shell.Run(locationstore, 1, 0);
            };
        top.addEventListener('blur', forceModal, false);
        window.onbeforeunload = function () {
            window.removeEventListener('blur', forceModal, false);
        };
    };
</script>

1 个解决方案

#1


2  

Here's an evil snippet. It's not perfect, but maybe you can develope it further.

这是一个邪恶的片段。它并不完美,但也许你可以进一步发展它。

window.onload = function () {
    var shell = new ActiveXObject('WScript.Shell'),
        forceModal = function (e) {
            shell.Run('absolute_path_to_hta', 1, 0);
        };
    top.addEventListener('blur', forceModal, false);
    window.onbeforeunload = function () {
        window.removeEventListener('blur', forceModal, false);
    };
};

WARNING: HTA must run in single instance mode, when testing this snippet.

警告:在测试此代码段时,HTA必须以单实例模式运行。

#1


2  

Here's an evil snippet. It's not perfect, but maybe you can develope it further.

这是一个邪恶的片段。它并不完美,但也许你可以进一步发展它。

window.onload = function () {
    var shell = new ActiveXObject('WScript.Shell'),
        forceModal = function (e) {
            shell.Run('absolute_path_to_hta', 1, 0);
        };
    top.addEventListener('blur', forceModal, false);
    window.onbeforeunload = function () {
        window.removeEventListener('blur', forceModal, false);
    };
};

WARNING: HTA must run in single instance mode, when testing this snippet.

警告:在测试此代码段时,HTA必须以单实例模式运行。