Solved

Using Autoit: Autorefresh a page in IE without losing focus

Posted on 2012-03-20
17
3,366 Views
Last Modified: 2013-11-19
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
0
Comment
  • 9
  • 6
17 Comments
 
LVL 29

Expert Comment

by:matrixnz
ID: 37809844
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

0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37811737
@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
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 500 total points
ID: 37812789
No problem, you can use either of the following:
NB1: I've added a hotkey so if you press Escape it will exit the script
Example1: This code will only refresh the first instance of an IE Window with 'Yahoo!' in the title every 10 Seconds.
Example2: This code will refresh all instances of IE Windows with 'Yahoo!' in the title every 10 Seconds.

Example 1
#NoTrayIcon
#include <IE.au3>

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

Local $oIE = _IEAttach('Yahoo!')

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

Func FNC_EXIT()
  Exit 0
EndFunc

Open in new window


Example2
#NoTrayIcon
#include <IE.au3>

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

While 1
  FNC_IEAttach()
  Sleep(10000)
WEnd

Func FNC_IEAttach()
Local $oIE, $i = 1
  While 1
    $oIE = _IEAttach("Yahoo!", "Title", $i)
      If @error = $_IEStatus_NoMatch Then ExitLoop
    _IEAction($oIE, 'refresh')
    $i += 1
  WEnd
EndFunc

Func FNC_EXIT()
  Exit 0
EndFunc

Open in new window

0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37813213
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.
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 37813831
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?
0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37814021
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.
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 37814131
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?
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37815934
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
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 37816300
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.
0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37816528
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
0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37816759
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
0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37816907
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."
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 37819275
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?
0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37829140
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.
0
 

Author Comment

by:Bobo--just_East_of_Madison
ID: 37834898
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Do we need servers??? 5 190
IE Edge 35 60
If-Then-Else ASP problem 6 49
Accurate Analytics (Not Google) 2 15
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now