在所有窗口上方运行hta

时间:2014-09-11 17:45:39

标签: javascript vbscript hta

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

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

我尝试过:

  • 提出的三项建议here
  • JavaScript解决方案here
  • 小VBScript here
  • 上述每一项都可能有十几个或更多微妙的变化。

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

我的解决方案

只是略微改编自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>

2 个答案:

答案 0 :(得分:3)

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

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);
    };
};

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

答案 1 :(得分:0)

<script type='text/vbscript'> 

window.setInterval "SetToFocus()", 100

        Function SetToFocus()
        window.focus()
        set objShell = CreateObject("shell.application")
        objShell.MinimizeAll
        End Function

</script>

这个婴儿将隐藏其他任何窗户,并置于顶部。