Jump to content

Need help to add a 10 seconds wait to a part of a JavaScript.


Recommended Posts

HI,

I'm trying to add a 10 seconds wait to a part of a script but i have problems to do this. I tried some stuff from the internet but i couldn't get it to work except one script, but with that i got a warning message about the Javascript running too slow.

function submit() {  for (var i = 0; i < cbo.length; i++) {    if (cbo[i].value==null==false && cbo[i].checked) {      try {        Act.Run(cbo[i].value.split("%CurDir%").join(basepath),1,true);        // Trying to add a 10 seconds wait.      }      catch(e) {        alert("COULD NOT EXECUTE:" + '\n' + cbo[i].value.split("%CurDir%").join(basepath));      }    }  }  // Trying to add a 10 seconds wait.  window.close();}
Edited by Mike88
Link to comment
Share on other sites


Here is how to use the timer object using Jscript

 <TITLE>Time Out Demo</TITLE> <HTA:APPLICATION ID="TmOut"  APPLICATIONNAME="TmOutDemo"  Border="Thin"  BORDERSTYLE ="Complex"  Caption="Yes"  Icon="%SystemRoot%\explorer.exe""  INNERBORDER ="No"  MaximizeButton="No"   MinimizeButton="Yes"   Scroll="No"   SCROLLFLAT ="No"          SingleInstance="Yes"  SysMenu="Yes"             WindowState="Normal"/> <STYLE>  Body   {    Text-Align:Center;Vertical-Align:Top;    Font-Size:9.25pt;Font-Weight:Bold;Color:Black;    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;        BackGround-Color:#EFE9E3;    Margin-Top:11;Margin-Bottom:1;    Margin-Left:4;Margin-Right:4;    Padding-Top:1;Padding-Bottom:1;    Padding-Left:4;Padding-Right:4;    Border-Top:0px Transparent;Border-Bottom:0px Transparent;    Border-Left:0px Transparent;Border-Right:0px Transparent;   }</STYLE><SCRIPT LANGUAGE='JScript'>//-> Resize And Place In Approx center window.resizeTo(301,151) window.moveTo(screen.availWidth/2-(301/2),screen.availHeight/2-(151/2))//-> Run Time Varible  var Tm1="";//-> Start The Timer   function Button1Click(){ Tm1=window.setInterval("TheTimeOut()",10000);   }//-> End Timer   function TheTimeOut(){ window.clearInterval(Tm1);    alert("Ten Seconds Time Out Completed")   }</SCRIPT><BODY><Button ID='Bn1' OnCliCk='Button1Click()'>10 Seconds</Button></BODY>
That will not work if he using a HTA with Jscript

WScript.Sleep 10000 'wait ten seconds

Try this in your .js file..

post-5386-0-59972900-1394908172_thumb.pn
Link to comment
Share on other sites

I tried my best but i couldn't get it to work, It won't pause 10 seconds before executing the other task. :(

<!--This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.This is only posted as example code and meant only to used as such.--><TITLE> TESTSCRIPT </TITLE><HTA:APPLICATION ID="TESTSCRIPT"  SCROLL="no"  SCROLLFLAT="no"  SINGLEINSTANCE="yes"  SHOWINTASKBAR="yes"  SYAMENU="yes"  MAXIMIZEBUTTON="no"  MINIMIZEBUTTON="yes"  CONTEXTMENU="no"  NAVIGABLE="no"  BORDER="thin"  BORDERSTYLE="normal"  INNERBORDER="no"  CAPTION="yes"  WINDOWSTATE="normal"  APPLICATIONNAME="TESTSCRIPT"  ICON="%SystemRoot%\explorer.exe"><script language="JavaScript">//-> Resize And Place In Approx Centerwindow.resizeTo(260,200)window.moveTo(screen.availWidth/2-(260/2),screen.availHeight/2-(200/2))//-> Objects For Runtimevar Act = new ActiveXObject("Wscript.Shell");var fso = new ActiveXObject("Scripting.FileSystemObject");var Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");//-> Runtime Variblevar c34 = String.fromCharCode(34);var HtaPath = TESTSCRIPT.commandLine.replace(c34,"");var basepath = new Array;var Tm1 = "";//-> Body OnLoad Functionwindow.onload=function() {  basepath = HtaPath.split('\\');  basepath.pop();  basepath = basepath.join('\\');  Act.CurrentDirectory = basepath;  setInterval("blinkit()",800);}//-> Blinking Text for <blink></blink> tagfunction blinkit() {  if (!document.all) return;  else {    for(i=0;i<document.all.tags('blink').length;i++) {      s=document.all.tags('blink')[i];      s.style.visibility=(s.style.visibility=="visible") ?"hidden":"visible";    }  }}//-> Start The Timerfunction pause(){ Tm1=window.setInterval("TheTimeOut()",10000);}//-> End Timerfunction TheTimeOut(){ window.clearInterval(Tm1);  alert("Ten Seconds Time Out Completed")}//-> Process Only Checked Checkboxesfunction submit() {  for (var i = 0; i < cbo.length; i++) {    if (cbo[i].value==null==false && cbo[i].checked) {      try {        display.innerHTML=(cbo[i].indicator);        Act.Run(cbo[i].value.split("%CurDir%").join(basepath),1,true);      }      catch(e) {        alert("COULD NOT EXECUTE:" + '\n' + cbo[i].value.split("%CurDir%").join(basepath));      }      pause();    }  }  display.innerHTML="<font color=\"#009900\"><b>Finished</b></font>";  pause();  window.close();}</script><body><table width="100%" align="center" border="1">  <td valign="top">    <table>      <tr>        <td class="c1">Start Calculator</td>        <td><input type="checkbox" id="cbo" name="checkbox1"          indicator="<b>Starting Calculator</b> <blink>Please wait...</blink>"          value='"%WinDir%\system32\calc.exe"' checked></input>        </td>      </tr>      <tr>        <td class="c1">Start Notepad</td>        <td><input type="checkbox" id="cbo" name="checkbox2"          indicator="<b>Starting Notepad</b> <blink>Please wait...</blink>"          value='"%windir%\system32\notepad.exe"' checked></input>        </td>      </tr>      <tr>        <td class="c1">Start Paint</td>        <td><input type="checkbox" id="cbo" name="checkbox2"          indicator="<b>Starting Paint</b> <blink>Please wait...</blink>"          value='"%SystemRoot%\system32\mspaint.exe"' checked></input>        </td>      </tr>    </table>  </td>  <tr>    <td colspan="3" align="center" id="display" class="display"></td>  </tr></table><table width="60%" align="center" style="margin:8px 0px 0px 0px;">  <tr>    <td align="center"><button type="button" id="btc" Style="width:100px;" onmouseover='this.className="button_hover"' onmouseout='this.className=""' onclick="submit()">Submit</button></td>    <td align="center"><button type="button" id="btc" Style="width:100px;" onmouseover='this.className="button_hover"' onmouseout='this.className=""' onclick="window.close();">Quit</button></td>  </tr></table></body>
Edited by Mike88
Link to comment
Share on other sites

Here is a hacked HTA that will do what you want

This works by creating a VBS script in the Temp folder

Contents Of VBS

Ts.Write("Wscript.Sleep(10000)")
It than runs the file wait for it to finish than it deletes it self.

fso.DeleteFile(Vbs)
Than it repeats the process over until all is done.

<!--  Hta And Script By Gunsmokingman AKA Jake1Eye   This HTA And Or Any Code Is The Property Of Gunsmokingman Or  Jake1Eye, Except Where Acknowledgement Comments Exists for Code  Written By Other Coders.   If Any Part Of This Code Is Used In Other Coding Project, There  Must Be An Acknowledgement Comments To The Original Coder Must Be   Included In Any Other Coding Project. --><TITLE> TESTSCRIPT </TITLE><HTA:APPLICATION ID="TESTSCRIPT"  SCROLL="no"  SCROLLFLAT="no"  SINGLEINSTANCE="yes"  SHOWINTASKBAR="yes"  SYAMENU="yes"  MAXIMIZEBUTTON="no"  MINIMIZEBUTTON="yes"  CONTEXTMENU="no"  NAVIGABLE="no"  BORDER="thin"  BORDERSTYLE="normal"  INNERBORDER="no"  CAPTION="yes"  WINDOWSTATE="normal"  APPLICATIONNAME="TESTSCRIPT"  ICON="%SystemRoot%\explorer.exe"><script language="JavaScript">//-> Resize And Place In Approx Centerwindow.resizeTo(260,200)window.moveTo(screen.availWidth/2-(260/2),screen.availHeight/2-(200/2))//-> Objects For Runtime var Act = new ActiveXObject("Wscript.Shell"); var fso = new ActiveXObject("Scripting.FileSystemObject"); var Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");//-> Runtime Varible var c34 = String.fromCharCode(34); var HtaPath = TESTSCRIPT.commandLine.replace(c34,""); var basepath = new Array;//-> Body OnLoad Function  window.onload=function(){basepath = HtaPath.split('\\');   basepath.pop();   basepath = basepath.join('\\');   Act.CurrentDirectory = basepath;   setInterval("blinkit()",800);  }//-> Blinking Text for <blink></blink> tag    function blinkit(){if(!document.all) return;    else{    for(i=0;i<document.all.tags('blink').length;i++) {      s=document.all.tags('blink')[i];      s.style.visibility=(s.style.visibility=="visible") ?"hidden":"visible";   }}}//-> Hack To Pause The Script   function pause(){var Vbs =Act.ExpandEnvironmentStrings("%Temp%\\VbsTimeout.vbs")     var Ts=fso.CreateTextFile(Vbs)     Ts.Write("Wscript.Sleep(10000)")     Ts.Close()     Act.Run(Vbs,1,true)     fso.DeleteFile(Vbs)   }//-> Process Only Checked Checkboxes   function submit(){    for (var i = 0; i < cbo.length; i++) {    if (cbo[i].value==null==false && cbo[i].checked){try{     display.innerHTML=(cbo[i].indicator);             Act.Run(cbo[i].value.split("%CurDir%").join(basepath),1,true);     display.innerHTML="<blink><B>Processing Please Wait</B></blink>".fontcolor("#005335")      pause();}     catch(e){alert("COULD NOT EXECUTE:\n"+cbo[i].value.split("%CurDir%").join(basepath));}         }}     display.innerHTML="<blink><b>Finished</b></blink>".fontcolor("#005335");    pause();window.close();   }</script><body> <table width="100%" align="center" border="1">  <td valign="top"><table><tr><td class="c1">Start Calculator</td>   <td><input type="checkbox" id="cbo" name="checkbox1" indicator="    <b>Starting Calculator</b> <blink>Please wait...</blink>"   value='"%WinDir%\system32\calc.exe"' checked></input>  </td></tr>  <tr><td class="c1">Start Notepad</td>           <td><input type="checkbox" id="cbo" name="checkbox2" indicator="    <b>Starting Notepad</b> <blink>Please wait...</blink>"   value='"%windir%\system32\notepad.exe"' checked></input>  </td></tr>  <tr><td class="c1">Start Paint</td>   <td><input type="checkbox" id="cbo" name="checkbox3" indicator="    <b>Starting Paint</b> <blink>Please wait...</blink>"   value='"%SystemRoot%\system32\mspaint.exe"' checked></input>  </td></tr>  </table></td>  <tr> <td colspan="3" align="center" id="display" class="display"></td></tr> </table> <table width="60%" align="center" style="margin:8px 0px 0px 0px;"> <tr>  <td align="center"><button type="button" id="btc" Style="width:100px;"    onmouseover='this.className="button_hover"' onmouseout='this.className=""'    onclick="submit()">Submit</button></td>  <td align="center"><button type="button" id="btc" Style="width:100px;"    onmouseover='this.className="button_hover"' onmouseout='this.className=""'    onclick="window.close();">Quit</button></td> </tr></table> </body>
If you did not write the blink function could you add a comment to the original coder or a link address to where you found it.
Link to comment
Share on other sites

You should of been able to figure this out, it was simple

Change to this function

//-> Hack To Pause The Script   function pause(t){var Vbs =Act.ExpandEnvironmentStrings("%Temp%\\VbsTimeout.vbs")     var Ts=fso.CreateTextFile(Vbs)     Ts.Write("Wscript.Sleep("+t+")")     Ts.Close()     Act.Run(Vbs,1,true)     fso.DeleteFile(Vbs)   }
And than make the changes like so

//-> Process Only Checked Checkboxes   function submit(){    for (var i = 0; i < cbo.length; i++) {    if (cbo[i].value==null==false && cbo[i].checked){try{     display.innerHTML=(cbo[i].indicator);             Act.Run(cbo[i].value.split("%CurDir%").join(basepath),1,true);     display.innerHTML="<blink><B>Processing Please Wait</B></blink>".fontcolor("#005335")      pause(3000);}     catch(e){alert("COULD NOT EXECUTE:\n"+cbo[i].value.split("%CurDir%").join(basepath));}         }}     display.innerHTML="<blink><b>Finished</b></blink>".fontcolor("#005335");    pause(7000);window.close();   }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...