5

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.

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 component (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>

3 Answers 3

4

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.

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

2
  • MinimizeAll minimized itself as well and when it minimizes itself, it wants to be on top, so it minimizes everything and so on... Sep 17, 2022 at 12:49
  • Just add WINDOWSTATE="maximize" on the HTA: application and you're good Oct 5, 2022 at 8:51
-2
<script type=text/vbscript">
    set objAPP=createobject("Shell.application") 
    Do
    wscript.sleep 500
    objAPP.AppActivate"Your Window Name"
    Loop
</script>
2
  • 3
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 29, 2022 at 15:47
  • 1
    An infinite loop like that is going to waste a lot of CPU cycles. Add a wscript.sleep 500 between the Do and the Loop to keep it's impact minimal.
    – LesFerch
    Jan 29, 2022 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.