2

I have written a HTA for some task to be done. I have used CSS within it. The issue is that the page is a bit distorted (layout is not proper, buttons are misplaced), and requires a refresh/reload to have it in proper format. Hence I wanted a workaround to have the HTA to reload just ONCE after opening.

I tried writing various codes in Window_onLoad to reload the window, but it causes the window to reload infinitely (since after every reload Window_onLoad gets fired). Hence required something which could reload just once and automatically, that too as soon as window is loaded, since I don't want to keep the users waiting to have a proper view of application.

Below is the code :

body
{
  
 margin:          0;
 padding:         0;
 background-color: #000;
 font-family:     'lucida grande', arial, tahoma, sans-serif;
}

#container
{
 margin:          0 auto;
 padding-top:0;
 width:           100%;
 position:        static;
 background-color:  #222;
}

#header
{
 margin:          0 auto;
 width:           100%;
 height:          800px;
 background:      transparent url('p1.jpg');
 background-size: 50% 50%; 
 
}

.headtitle
{
 position:        relative;
 font-family:     Times;
 font-size:       40px;
 color:           #FFF;
 top:             20px;
 left:            18px;
}

 

form {
  padding:  20px 0;
  position: relative;
  top:      80px;
  margin: 0 auto 10px 300px; 
}

form input {
outline: 0;
  border: 0px 
  background-color: rgba(255, 255, 255, 0.2);
  width: 200px;
  border-radius: 15px;
  padding: 1px 15px;
  margin: 0 auto 10px auto;
  display: block;
  text-align: center;
  font-size: 18px;
  color: black;
  -webkit-transition-duration: 0.25s;
          transition-duration: 0.25s;
 behavior: url(PIE.htc);
  font-size: 90%;
  
  }
  
  form input:hover {
  background-color: rgba(255, 255, 255, 0.4);
}
form input:focus {
  background-color: white;
  width: 300px;
  color: #53e3a6;
}
  
 
<html>
<head>
 <HTA:APPLICATION
   APPLICATIONNAME="Simple HTA"
   BORDER="NONE"
   MaximizeButton="no"
   Scroll="NO"
   SYSMENU="YES">
   
 <title>PrOtOtYpE</title>
 <link rel="stylesheet" type="text/css" href="style.css" />
 <script language="VBScript">

 SUB RunFile 
  SET WshShell = CreateObject("WScript.Shell")
  WshShell.Run "Z:/SSH/SshClient.exe"
 End SUB
 
 SUB CloseWindow
  self.close
 End SUB

 
 SUB Window_onLoad
        window.resizeTo 800,700
 End SUB 

 </script>
  
</head>
 
<body>
 <div id="container"> 

  <div id="header">
    <div class="headtitle">PrOtOtYpE</div>
    
 <form class="form" name="form">
   <input type="button" name="button" value="App Web Server 505" onclick="RunFile"/> 
   <input type="button" name="but" value="App Web Server 506" onclick="RunFile"/> 
   <input type="button" name="but" value="DB Server 178" onclick="RunFile"/> 
   <input type="button" name="but" value="DB  Server 177" onclick="RunFile"/> 
   <input type="button" name="but" value="Close" onclick="CloseWindow"/> 
 </form>
   
</div>
</div>
 </body>
 </html>
 
 
Prateek Jaiswal
  • 145
  • 2
  • 15
  • 3
    Why don't you try to fix the issues with the layout instead of finding a workaround? – Teemu Dec 21 '15 at 09:41
  • The Problem started off after using PIE.htc (for rounded corners). Before it, the HTA loaded properly. Cannot think of any solution. – Prateek Jaiswal Dec 21 '15 at 09:49
  • Not using PIE.htc comes to mind ... – Ansgar Wiechers Dec 21 '15 at 10:15
  • Round borders are required :) – Prateek Jaiswal Dec 21 '15 at 10:19
  • 2
    @PrateekJaiswal Please read http://stackoverflow.com/a/19570684/1169519 , you can use for example IE9 mode to get rounded corners. – Teemu Dec 21 '15 at 10:53
  • Thanks a lot @Teemu adding the Meta tag is working perfectly fine for me. Sincethe rot cause is elimnated now, no need of workaround :) – Prateek Jaiswal Dec 21 '15 at 12:07
  • Oops @Teemu , i seem to have run into trouble. Using meta tag for sure solved the issue for rounded borders, BUT it rendered VBScript useless. On analysis, found that IE9 and above were meant, not to support HTA and hencethe issue. Since VBS is a very important part of HTA, using meta wont work, We have to have a workaround. :( – Prateek Jaiswal Dec 21 '15 at 12:17
  • But IE9 supports HTA, and VBScript is supposed to work in IE9 too (VBS was removed in IE11 on web pages only). What actually do you mean with "rendered VBScript"? Scripts are not rendered, they are parsed. – Teemu Dec 21 '15 at 12:24
  • Yes, I mean it guess VBS is not being parsedafter addng meta tag, i get following error , "is unidentified". Allow me sometime so that i can provide the snippet of code from HTa, over here :) – Prateek Jaiswal Dec 21 '15 at 12:41
  • Are you perhaps using monikers like `vbscript:` in your `hrefs` to call your Sub Procedures? Consider fixing your event handlers and you will be able to use Standards mode. – user692942 Dec 21 '15 at 12:48
  • 1
    Ideally we need to see your HTA code to advise better. – user692942 Dec 21 '15 at 12:49
  • Hi @Lankymart, i have edited the question to include the code too now . :) – Prateek Jaiswal Dec 22 '15 at 04:38
  • the layout appears perfect in the browser though, its distorted in HTA, and requires one reload. – Prateek Jaiswal Dec 22 '15 at 05:07
  • Have you tried an absolute path in the reference to PIE.htc `behavior: url(PIE.htc);`? – langstrom Dec 22 '15 at 21:20

1 Answers1

0

In onload set a flag.

'Making a public variable
Dim FirstRunFlag

SUB Window_onLoad
        window.resizeTo 800,700
        If FirstRunFlag=0 then 
                window.refresh
                FirstRunFlag=1
       End If
End SUB 

or make this the first script run in the head before the style sheets.

<html>
<head>
<script language=vbscript>

    window.resizeTo 800,700
</script>
<style>
etc etcetc
</style>
</head>
<body>ra, ra, ra.</body>
</html>
bgalea
  • 67
  • 2
  • 1
    Hi @bgalea thank you for the beautifully simple workaround. The !st option however is not working as window.refresh seems to be uncrecognizable by the HTA engine. The 2 nd option though works perfectly fine and there is no distortion, hence no need of a Reload. Can you explain how does this work, so that in future i can keep this in mind :) – Prateek Jaiswal Dec 23 '15 at 04:55
  • window.refresh doesn't work. Try this: window.location.reload() – Mattman85208 Jul 31 '17 at 16:35