Anurag Rana
Anurag Rana

Reputation: 1466

Wait function in VBscript HTML application

I am developing a html page in which I am using vbscript as scripting language i.e. VBScript in head section of html page. I want to insert the explicit wait in the execution of some function.

In Excel macro Application.wait waitTime works great but in html page I am not able to achieve what I want.

Can someone please suggest any code snippet which can help me to insert some wait say 10 seconds?

Upvotes: 3

Views: 2490

Answers (2)

Abbas
Abbas

Reputation: 6886

You can use the setTimeout() to delay execution of your code. Put all your vbscript code into a sub, lets say you call it mySub, and then call setTimeout:

<script type="text/vbscript">
    Sub mySub
        'Your code goes here
        MsgBox "Executed after delay"
    End Sub

    window.setTimeout "mySub()", 10000, "VBScript"
</script>

Note the second argument is duration of delay in milliseconds.

Upvotes: 5

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

Another solution, which could be used more "naturally", but only with seconds granularity:

<script type="text/vbscript">
Set sh = CreateObject("WScript.Shell")

Sub Sleep(seconds)
  sh.Run "%COMSPEC% /c ping -n " & seconds+1 & " 127.0.0.1", 0, True
End Sub

...
Sleep 10
...
</script>

Upvotes: 1

Related Questions