问题描述
我有一个HTML应用程序,希望保留在所有窗口的顶部(也就是说,如果另一个窗口被打开/切换到该窗口,我希望该窗口覆盖它). JavaScript解决方案在Windows 7/IE9模式下不起作用(不确定是哪种阻碍,也不能更改),并且VBScript解决方案似乎完全失败或依赖于外部组件.我也不能使用模式对话框,因为我需要将其置于所有其他窗口之上,而不仅仅是其父窗口.
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.
请勿将此标记为,因为那样(遗憾的是仍未得到答复)问题是指在其他窗口上方打开,而不保持堆栈位置.
And don't mark this as a duplicate of https://stackoverflow.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.
我尝试过的事情:
- Three of the suggestions outlined here.
- The JavaScript solution here.
- The little VBScript here.
- Probably a dozen or more subtle variations on each of the above.
请记住,我无法下载额外的组件(没有autoit或nircmd).都应将其集成到单个文件中,最好是hta,而不是zip.
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.
仅略微修改了Teemu的解决方案,主要是为了便于携带(以防万一).
Only very slightly adapted from Teemu's solution, mainly for portability (just in case).
<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>
推荐答案
这是一个邪恶的代码段.它不是完美的,但是也许您可以进一步开发它.
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);
};
};
警告:测试此代码段时,HTA必须在单实例模式下运行.
WARNING: HTA must run in single instance mode, when testing this snippet.
这篇关于在所有窗口上方运行hta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!