title: Running an hta above all windows
body: <p>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.</p>
  
  <p>And don't mark this as a duplicate of <a href="https://stackoverflow.com/questions/24539339/how-to-open-a-hta-window-on-top-of-all-other-windows">https://stackoverflow.com/questions/24539339/how-to-open-a-hta-window-on-top-of-all-other-windows</a> because that (unfortunately still unanswered) question refers to opening above other windows, not maintaining stack position.</p>
  
  <p>What I have tried:</p>
  
  <ul>
  <li>Three of the suggestions outlined <a href="http://social.technet.microsoft.com/Forums/scriptcenter/en-US/d1948ca9-5066-481b-822f-145664890437/hta-always-on-top" rel="nofollow noreferrer">here</a>.</li>
  <li>The JavaScript solution <a href="http://www.visualbasicscript.com/Always-On-Top-m70146.aspx" rel="nofollow noreferrer">here</a>.</li>
  <li>The little VBScript <a href="http://www.visualbasicscript.com/HTA-above-other-windows-m67113.aspx" rel="nofollow noreferrer">here</a>.</li>
  <li>Probably a dozen or more subtle variations on each of the above.</li>
  </ul>
  
  <p>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.</p>
  
  <h2>My Solution</h2>
  
  <p>Only very slightly adapted from Teemu's solution, mainly for portability (just in case).</p>
  
  <pre><code>&lt;script language="javascript"&gt;
      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);
          };
      };
  &lt;/script&gt;
  </code></pre>