auto refresh for ie

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

auto refresh for ie

Post by theonex » Thu May 10, 2012 12:41 pm

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.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 16, 2012 9:55 am

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Post by theonex » Thu May 17, 2012 11:11 pm

hi mtettmar

thanks for your reply and suggestion i am not so good with VBscripts. by any chance could you write a small script monitoring IE busy and how to creat a loop with timeout. i would really appreciate your help

thank you

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri May 18, 2012 11:14 am

Right, good job I'm not too busy today eh? Here's one solution:

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
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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Post by theonex » Fri May 18, 2012 7:24 pm

thank you sooooooo much mtettmar i really appreciate that.. i hope this will also be useful to others out there

many thanks again

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts