views:

1173

answers:

2

Is there a way to stop the WebBrowser control from causing its parent form to bring itself to the front?

If you use the InvokeScript method to invoke a JavaScript function that calls focus() on an iframe within the main parent document, it will cause the window to bring itself directly to the front(or atleast cause the taskbar icon to start flashing). Is there a way to prevent this from happening?

Update:

I've found a temporary answer to my problem.

When the WebBrowser's parent Form's Deactive event is fired, I remove the WebBrowser from its container, and re-add it when its old parent form is activated again.

It's kind of hacky, but it works. I'm open to any better suggestions, though.

+4  A: 
Abel
I like this answer, though it seems a bit convoluted for what I need. That is, I have a specific setup for my own app so my hacky method isn't going to be a problem for this instance. However, I'm going to integrate this into another app. Thank you!
rossisdead
I totally agree, it is a complex workaround, simply because there's no such thing as `if is_flashing then`. I wished there was another way, but afaict, there isn't, really.
Abel
A: 

Implement IProtectFocus::AllowFocusChange in an object

Implement IServiceProvider on the same object that implements IOleClientSite, then respond to a IServiceProvider::QueryService for SID_SProtectFocus with an object that exposes IProtectFocus

This is a new interface in IE7, so old versions are out of luck.

Sheng Jiang 蒋晟