tags:

views:

54

answers:

1

Hi i have a windows application where i show a webbrowser, i have a button that removes the browser (its a preview) and goes to another "view" in my application (another tab). My problem is that my users are getting advanced, they build HTML with links (and its ok) but the links may spawn new browser windows (IExplorer), and my button needs to close these windows, but how?

I have made some code to traverse all eht windows that ends with "Windows Internet Explorer", ahd it all seems to work - but how do i close them? I am trying to do it like this:

SendMessage((int)hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);

It seems to work, but the browser pops up a dialog asking me if i want to close the tab of all the tabs...how to work around/solve this?

Cheers,

+1  A: 
  1. walking over all top level iE windows and closing them is a bad idea, unless you are guaranteed users can't launch ie and browse the Internet on their own. Otherwise, you might actually lose user data (say an email or a blog post the user has been working on in the last half an hour)

  2. You can't easily work around that dialog without modifying the per-user IE settings. Your other option is to look for that dialog and click the yes button, but that would be fragile and is not guaranteed to continue working if the user upgrades to IE9.

  3. You could potentially prevent opening links in new window by listening to BeforeNavigate event and allowing only navigations that are guaranteed to happen in your control. However, there are scenarios where IE might still decide to open new window.

Franci Penov
+1 for #1. I wouldn't like for an app to indiscriminantly close all of my IE windows.
JMarsch