hello
I would appreciate any help or suggestions on this topic I have couple of scripts running without any problems however I have a problem with the loading of websites sometimes and a simple refresh fixes this issue for me. I was wondering if it’s possible to write a little script that will run on a loop monitoring ie explorer and if ie explorer status stays busy lets say for 10 seconds will send a refresh command.
auto refresh for ie
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
The "best" approach would be to use some VBScript to monitor IE's busy property, create a loop with a timeout and then call IE's refresh function. Search these forums for "internetexplorer.application". Ideally you'd need the script to create the IE instance, although it is possible to "GET" an existing IE instance. There's code on this forum to do this.
If you're not comfortable with that you could in theory use the screen text capture functions to monitor the text of IE's status bar, in a loop, use the Timer function to monitor elapsed time at the same time and if needed, send F5 to IE.
If you're not comfortable with that you could in theory use the screen text capture functions to monitor the text of IE's status bar, in a loop, use the Timer function to monitor elapsed time at the same time and if needed, send F5 to IE.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Right, good job I'm not too busy today eh? Here's one solution:
Comments should explain it.
So first thing we do is "attach" to the given IE window so that we can "hook" into it. Then we have a function which will wait for IE to cease being busy by looking at IE's busy property OR a given millisecod timeout, whichever comes first. This function returns true if IE stopped being busy before the timeout occurs, false if the timeout occurs first.
So in our main script we set up a loop which continually monitors IE by running this WaitWithTimeout, set for a 10 second timeout. And if the timeout occurs (IE has been busy for 10 seconds) then we issue a refresh.
Code: Select all
//VBS library code
VBSTART
Dim IE
'Attaches to an existing instance of IE with matching URL
Sub GetIE(URL)
Dim objInstances, objIE
Set objInstances = CreateObject("Shell.Application").windows
If objInstances.Count > 0 Then '/// make sure we have instances open.
For Each objIE In objInstances
If InStr(objIE.LocationURL,URL) > 0 then
Set IE = objIE
End if
Next
End if
End Sub
'Waits while IE is busy or specified timeout occurs
'returns true if IE not busy before timeout elapsed
Function WaitWithTimeout(milliseconds)
nStartTime = Timer
while (IE.Busy AND (Timer < nStartTime+milliseconds))
Sleep(10)
Wend
'did we timeout or not? true=all ok, didn't timeout, false=we timed out
if (Timer => nStartTime+milliseconds) then
WaitWithTimeout=false
else
WaitWithTimeout=true
end if
End Function
VBEND
//MAIN script execution starts here
//attach to the IE instance with given URL
VBRun>GetIE,www.google.co.uk
//monitor loop - keeps checking the wait state/timeout
Label>monitor
//wait for busy or 10 second timeout
VBEval>WaitWithTimeout(1000),WaitOk
If>WaitOk=False
//timed out so refresh IE
MessageModal>timedout
VBEval>IE.Refresh,nul
Endif
Wait>0.02
Goto>monitor
So first thing we do is "attach" to the given IE window so that we can "hook" into it. Then we have a function which will wait for IE to cease being busy by looking at IE's busy property OR a given millisecod timeout, whichever comes first. This function returns true if IE stopped being busy before the timeout occurs, false if the timeout occurs first.
So in our main script we set up a loop which continually monitors IE by running this WaitWithTimeout, set for a 10 second timeout. And if the timeout occurs (IE has been busy for 10 seconds) then we issue a refresh.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?