admin管理员组文章数量:1391960
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 ponents. 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 because that (unfortunately still unanswered) question refers to opening above other windows, not maintaining stack position.
What I have tried:
- 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.
Keep in mind that I can't download an extra ponent (no autoit or nircmd). It should all be integrated into a single file, preferably an hta, but not a zip.
My Solution
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>
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 ponents. 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./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.
What I have tried:
- 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.
Keep in mind that I can't download an extra ponent (no autoit or nircmd). It should all be integrated into a single file, preferably an hta, but not a zip.
My Solution
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>
Share
Improve this question
edited May 23, 2017 at 11:51
CommunityBot
11 silver badge
asked Sep 11, 2014 at 17:45
ndm13ndm13
1,23914 silver badges20 bronze badges
3 Answers
Reset to default 4Here'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.
<script type='text/vbscript'>
window.setInterval "SetToFocus()", 100
Function SetToFocus()
window.focus()
set objShell = CreateObject("shell.application")
objShell.MinimizeAll
End Function
</script>
This baby will hide any other windows and make itself on top.
<script type=text/vbscript">
set objAPP=createobject("Shell.application")
Do
wscript.sleep 500
objAPP.AppActivate"Your Window Name"
Loop
</script>
本文标签: javascriptRunning an hta above all windowsStack Overflow
版权声明:本文标题:javascript - Running an hta above all windows - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744714631a2621329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论