2

I'm working on a legacy software that, among other, have a button that opens a new internet explorer windows and navigate to a specific address within it. The browser controller would hold the reference to the window so that if the button is pressed again - the same window will be used to be navigated into it again.

This basically works with SHDocVw.InternetExplorer object and I just use the "navigte" method and it works perfectly... on Windows XP (IE 6-8).

Our client wishes to upgrade to windows 7 and it seems like MS decided to screw this specific piece of code (and add security in the process :) ) by raising a "OnQuit" event every time you navigate to a different domain from what you were in (so, if I open a new window using "Browser = new SHDocVw.InternetExplorer();" and than use "Browser.Navigate("www.google.com") the Browser object will be marshalled.

Reading through this issue it seems I wasn't the only one with this problem and the suggested solution was to find my IE window that I opened and connect to it, so I have this function:

private void FindIwdBrowser()
{
    if (Browser != null)
        return;

    SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
    foreach (var window in shellWindows)
    {
        SHDocVw.InternetExplorer foundBrowser = ((SHDocVw.InternetExplorer)window);
        if (!foundBrowser.Name.EndsWith("Internet Explorer"))
            continue;

        if (foundBrowser.LocationURL.StartsWith(config.UrlTemplate.Substring(0, config.UrlTemplate.IndexOf("?"))))
        {
            Execute.OnUIThread(() =>
            {
                foundBrowser.OnQuit += Browser_OnQuit;
                Browser = foundBrowser;
            });
            return;
        }
    }
}
  • Execute.OnUIThread - I use caliburn micro, wanted to make sure it's not a thread issue
  • config.UrlTemplate - the URL I'm navigating to

This solution works... sort of, the only problem is that if it's the first tab in a new window that I open - it doesn't recognize it, if it's the second one (even if I close the first one thereafter) it does work.

after almost a week of frantically searching the internet I decided to ask the great minds here - maybe you could figure out why it works only half the times, or if my tactic is flawed and I should try a different approach.

I'd rather not to use a web client control as the website I'm navigating to is also a 3rd party and tends to crash a lot, and if it'll be within a webclient I create - the client might blame our software, which I would rather avoid.

Thanks in advance!

Koby Yehezkel
  • 208
  • 4
  • 11
  • But how regular WebBrowserControl can crash your software? Maybe the Web site that's opened using IE it's not brilliant in terms of stability, but a Web site inside an embedded IE won't crash your app... – Matías Fidemraizer Aug 27 '14 at 14:52
  • since my client is consisted of people with short term memory (I.E. - blaming my software even though I had 2 bugs in the past 2 years and the ones creating the website had... a lot more) I would rather to make sure it is visibly separated, if I won't have a choice naturally I'll do that but I would really like to avoid that. Besides - it's a really interesting trivia to me :) – Koby Yehezkel Aug 27 '14 at 14:58
  • And what about opening the WebBrowserControl in a child windows with a text like "Powered by Internet Explorer", or even better!! "Powered by Internet Explorer 6". This would redirect hate to Microsoft :D Uhm... BTW I would choose the solution that gives me an easy approach rather than avoiding a possible client hate complicating the whole solution – Matías Fidemraizer Aug 27 '14 at 15:02
  • Lol! well, MS have been providing me with work since 1996, so I wouldn't want too much hate directed at them, and the control uses compatibility mode (changeable via registry value which I do not have access to), so... I can't since I do not provide setup file, only an executable. – Koby Yehezkel Aug 27 '14 at 15:07
  • You can even write that registry key from the whole executable. Why not? – Matías Fidemraizer Aug 27 '14 at 15:09
  • Permissions issues... My client is a financial company that doesn't allow 3rd party softwares too much freedom. I could twist their hands, but they might not like it. – Koby Yehezkel Aug 27 '14 at 15:13
  • Argh! Well, good luck, let's see if someone can come with a fix to your approach... – Matías Fidemraizer Aug 27 '14 at 15:18
  • Well, I found the solution, Aperantly using flags have no effect on navigate method when I'm using TargetFrameName Browser.Navigate(url, flags, "ClientToolbar"); was the root of my issues, changing it to Browser.Navigate(url, flags, "_self"); did the trick, regardless of which flags I've been using, now it's time to find out why :) ... such an anti-climatic end to my search :( – Koby Yehezkel Aug 27 '14 at 16:25
  • Nice. If you find a solution, it's absolutely posssible to auto-answer the question! – Matías Fidemraizer Aug 27 '14 at 17:36

0 Answers0