Question: I’m using SHDocVw.InternetExplorer APIs in my Vb.Net WinForms application to capture requests sent from IE in my application.

As given on [this](http://msdn.microsoft.com/en-us/library/aa768337%28v=vs.85%29.aspx) link

> 
> "The NewWindow3 event is only fired when a new instance of Internet
>  Explorer is about to be created. Calling showModalDialog or
>  showModelessDialog does not trigger an event because they are not new
>  instances of Internet Explorer"
> 
> 
> 

I am trying to automate user actions in Internet Explorer for automated testing. So I want to know that due to some user action a modal dialog is opened or some alert window is opened.

So my question is:

* How do I know that a modal dialog window is opened in Internet Explorer?
* Is there any other event raised by Internet Explorer in this case?
* If it's not possible directly then is there some other way to handle this scenario?

Answer: 
The event you're looking for probably doesn't exist, however there's a number of workarounds for detecting if a modal is open. 

You can use jquery to add/ remove classes on the modal: [Can I check if Bootstrap Modal Shown / Hidden?](https://stackoverflow.com/questions/19674701/can-i-check-if-bootstrap-modal-shown-hidden)

You can check the console: [check if jquery reveal modal is active, do something](https://stackoverflow.com/questions/19822597/check-if-jquery-reveal-modal-is-active-do-something)

I don't recommend the console approach, there's more to it like when the console's not open. 

I can think of several ways to solve your problem without caring about the event at all however, couldn't the modal talk to the IE page and then use the API to talk to your app? You can use show() & hide() to change the state of the modal and when that state changes fire additional code to do what you need to. 

Another option is to save values to a database and read them back in the app (doesn't require the API obviously). 

If none of these sound good, perhaps you should tell us exactly what you're trying to accomplish from a functional standpoint and we'll be able to architect / give you a solution.
There is no a such event, but you can use some other approaches:

1. Webbrowser.Document.Window.Error is fired before modal window will
be displayed
2. You can implement INewWindowManager interface - I don't know exactly, but I think it can give some information to you
3. You can implement IDocHostUIHandler and use ShowUI method - but it executed not only for displaying new window, you should use it
carefully
4. IOleCommandTarget - 'Exec' method with cmdId
OLECMDID\_SHOWSCRIPTERROR, OLECMDID\_SHOWMESSAGE, OLECMDID\_SHOWFIND,
 OLECMDID\_SHOWPAGESETUP, OLECMDID\_SHOWPRINT means that new window
 will be opened