Jump to content
Sign in to follow this  
Juvigy

How to prevent IE to receive focus or pop on top

Recommended Posts

Juvigy

Hi Guys,

I have a script that manipulates IE page. The problem is that it popups the IE window on top of other windows. How can i prevent that? I tried making the window invisible, but it is affecting me as i don't see the window , but my current window looses focus and for example if i write an email - my outlook looses focus to the IE window and my keyboard input is piped out to IE. How can i prevent that?
 

Quote

This is how to reproduce , i think:

It happened to me several times, in several websites, some of them require log in,

so I will simply give you the HTML code that does it:

 

If you create a file called FocusTest.html, and put this in it:

Quote

 

<body onload="self.focus();">

Then this html page will steal focus every time when loaded.

In orer to test it, you need to open it with IE,

but because you're alraedy focussed on it, then you will not see the problem..

So after opening the file, do this:

Create a small AutoIt script, and put this inside:

Local   $hIntExp    =WinGetHandle("D:\SomeFolder\FocusTest.html - Windows Internet Explorer")
ControlSend($hExp,"","Internet Explorer_Server1","{F5}")

Then, run the script, while the IE window is not focussed,

and see what happens.

IE will take focus from whatever other window that was open.

And that's what I am trying to disable - to disable IE from taking focus from other applications when the focus is on them.

 

Edited by Juvigy
Added reproducer

Share this post


Link to post
Share on other sites
Danp2

Perhaps you should look at this from a different angle. Instead of trying to prevent the focus change, maybe you can identify where it happens in your script and then add some code to save/restore the focus.

Share this post


Link to post
Share on other sites
Juvigy

I thought about that , but i suspect that there are too many places in the script when that happens. I was hoping for more global solution. Something like :

_IEPropertySet($oIE,"NoFocus")

:)

Share this post


Link to post
Share on other sites
Danp2

There's code in the UDF to explicitly set focus to the document whenever an "about:" window is displayed. Other than that, you could take a look at the internal function __IELockSetForegroundWindow to see when / how it is being called.

Share this post


Link to post
Share on other sites
jdelaney

You can run the script on a different user session.  psexec can do that, or a scheduled task.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Juvigy

After some testing i found that that this only happens when IE has only one tab. IF i have an additional tab - even if a blank one - this never happens. So i have found an easy workaround for this issue, but i am still wandering why this happens if only one tab is open.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×