Link to home
Start Free TrialLog in
Avatar of Bobo--just_East_of_Madison
Bobo--just_East_of_MadisonFlag for United States of America

asked on

Using Autoit: Autorefresh a page in IE without losing focus

I would like to write something in AutoIT for IE that would refresh a page at a predetermined interval but without taking focus off the window you're in. For example, if I want www.yahoo.com to be refreshed every 10 seconds, but if I'm typing in Notepad, I don't want the focus to be taken off of that.

I've tried Yrefresh, but that takes focus off what you're doing, and could lead to mistakes, depending upon what you're doing.

This is not for server-side scripting; that is, I cannot put it on the WebPage I want refreshed
Avatar of matrixnz
matrixnz

You mean something like this:

#include <IE.au3>
Local $oIE = _IECreate("www.yahoo.com")
While 1
  Sleep(10000)
  _IEAction($oIE, 'refresh')
WEnd

Open in new window

Avatar of Bobo--just_East_of_Madison

ASKER

@martrixnz

Sweet...but...I don't need to create the browser instance, I need it to execute the refresh command on an existing browser tab, which could be identified by the title of the tab or title of the page.

I believe I failed to mention that; apologies.

If it is not proper EE etiquette to request additional assistance in the original request, I will reward full points to you for this and then open a new instance for the additional question.

Best,

Bobo
ASKER CERTIFIED SOLUTION
Avatar of matrixnz
matrixnz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works like a charm. Is there any way to have it refresh without the IE window (tab) taking focus off what the user may be doing at the time? Which is essential that focus is not removed.
Not 100% sure what you mean, I opened IE Window with two tabs, one to www.yahoo.com and the other to www.google.com I'm currently writing this in firefox without the focus being taken, I'm using the second script above on Windows 7 x64.  Can you explain what's happening on your system?
Sure. I run the autoit executable and was typing in notepad. When the five seconds elapsed, focus was taken off the notepad typing I was doing (albeit, it wasn't too long, but it caused a bit of a "stutter" and consequently an error), the browser refreshed, and then I went back to typing without a problem. But as the five seconds elapse, focus it taken off for a second or two. I'm using IE8; Windows XP SP3; 32-bit.
It doesn't appear to be a problem in Windows 7, I'll see if I can get a Windows XP System to test on.  What was the error you received "a bit of a stutter and consequently an error)  Can you also test by running directly in Scite and see if any error messages popup in the Scite Console Window, to run in Scite just click Tools » Go

If anything it appears that the script is taking focus not the browser, if the browser was taking focus it would come to the front, have you got any other settings within your script?
No error received, but while I was typing in notepad with the script running, the second or two of lost focus resulted in a typing error. I was typing "The quick, brown fox jumped over the lazy dogs" and when focus came off for the browser refresh, the loss of focus caused an error in my typing, not an error generated by the program.

The browser isn't coming to the front, so maybe I'm using the wrong terminology.

The screen shot I've attached are images from title bar of IE and Notepad. The grey is the loss of focus, but then focus is restored after the program finished executing. But for the one or two seconds focus is lost, I can no longer type in Notepad; typing is interrupted, and I either make a mistake, or have to re-type. But focus is restored after the program finishes executing

Here is copy of the script as I have it:

#NoTrayIcon
#include <IE.au3>

HotKeySet('{ESC}', 'FNC_EXIT')

Local $oIE = _IEAttach('Webtop')

While 1
  Sleep(10000)
  _IEAction($oIE, 'refresh')
WEnd

Func FNC_EXIT()
  Exit 0
EndFunc
                                            

Open in new window


I am, however, running it as an .exe file; but I don't think this matters as I've tried it running the executable and the .au3 version of the file.

I have Windows 7 available to me, so I will test there and see what happens.

Thank you for your assistance thus far.

--Bobo
focus-loss-example.JPG
Can't seem to get the same results, have tested on Windows XP Virtual Machine and ran the same test as yourself and no problems refreshing the page while typing in NotePad., so not really sure why your getting different results.
OK. I'll look into this further. And I'll try on Windows 7 and let you know what I find.

Thanks for your help thus far.

Best,

Bobo
OK, so I tested in Windows 7 and it executed as you indicated; no focus was taken off of what I was doing.

I'll award points for this and then open up a new questions for the focus problem in XP.

Thanks,

Bobo
I guess I spoke to soon. I'm not sure why, but after a few tries in Windows 7, it started removing focus again. I'm not sure how I can troubleshoot this. And I'm wondering why focus wasn't lost on the first attempt, but now it is occurring. Strange.

Maybe I can post this question in another forum, unsure how to categorize it.

Could it be how I'm compiling it? I'm compiling it in SCite by clicking "Tools," and then "Compile."
Sorry for the delay, Easter Holidays, compiling wouldn't be the issue, what happens if you make the refresh every 20 seconds i.e. Sleep(20000) I'm wandering if it's the page your refreshing, I left it on Yahoo! for several hours and still not having the same issue as yourself, if you change the url to www.yahoo.com and leave it does it still lose focus?
Yeah, you're right; I think it's the page; here's what I can tell you about it:

Server is Apache Tomcat
It's SSL
Log in is required
Doc type is HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"

Let me know if there's any other information I can provide that would help.
This is an internal URL, so I would be unable to provide you with the location.