wpf webbrowser control and google maps, overlays gray image

Questions


I have been using the webbrowser control in c# to render google maps for a long time. Recently, google maps now loads up and then a gray box is overlaid. See the image

http://www.condoresorts.com/Debug/webdebug.png

Anyone have the slightest idea what would cause this?

this.webBrowser1.DocumentText = @"<iframe width=""425"" height=""350"" frameborder=""0"" scrolling=""no"" marginheight=""0"" marginwidth=""0"" src=""https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed""></iframe><br /><small><a href=""https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7"" style=""color:#0000FF;text-align:left"">View Larger Map</a></small>";

Noseratio was correct. I followed his link, implemented the code for the project and it no long had that behavior.

amespace WebBroweerControls
{
public class Form1
{
System.Windows.Forms.WebBrowser webBrowser1 = null;

    public Form1(System.Windows.Forms.WebBrowser br)
    {

        webBrowser1 = br;

        SetBrowserFeatureControl();



    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //DoNavigationAsync().ContinueWith(_ =>
        //{
        //    MessageBox.Show("Navigation complete!");
        //}, TaskScheduler.FromCurrentSynchronizationContext());


        //var html = "<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" " +
        //       "src="https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
        //       "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
        //       "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed">" +
        //       "</iframe>" +
        //       "<br /><small><a href="https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
        //       "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
        //       "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7" style="color:#0000FF;" +
        //       "text-align:left">View Larger Map</a></small>";

        webBrowser1.Navigate("http://www.condoresorts.com/Directions/PrintShares/Coyote%20Lakes/Pillars%20to%20Coyote%20Lakes.htm");
    }

    private async Task DoNavigationAsync()
    {
        TaskCompletionSource<bool> documentCompleteTcs = null;

        WebBrowserDocumentCompletedEventHandler handler = delegate
        {
            if (documentCompleteTcs.Task.IsCompleted)
                return;
            documentCompleteTcs.SetResult(true);
        };

        documentCompleteTcs = new TaskCompletionSource<bool>();
        this.webBrowser1.DocumentCompleted += handler;

        // could do this.wb.Navigate(url) here 
        this.webBrowser1.DocumentText = "<!DOCTYPE html><head><meta http-equiv='X-UA-Compatible' content='IE=edge'/></head>" +
            "<body><input size=50 type='text' placeholder='HTML5 if this placeholder is visible'/></body>";

        await documentCompleteTcs.Task;
        this.webBrowser1.DocumentCompleted -= handler;

        dynamic document = this.webBrowser1.Document.DomDocument;
        dynamic navigator = document.parentWindow.navigator;
        var info =
            "n navigator.userAgent: " + navigator.userAgent +
            "n navigator.appName: " + navigator.appName +
            "n document.documentMode: " + document.documentMode +
            "n document.compatMode: " + document.compatMode;

        MessageBox.Show(info);
    }

    private static void SetBrowserFeatureControl()
    {
        // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

        // WebBrowser Feature Control settings are per-process
        var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);

        // make the control is not running inside Visual Studio Designer
        if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0)
            return;

        SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode());
    }

    private static void SetBrowserFeatureControlKey(string feature, string appName, uint value)
    {
        using (var key = Registry.CurrentUser.CreateSubKey(
            String.Concat(@"SoftwareMicrosoftInternet ExplorerMainFeatureControl", feature),
            RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
            key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord);
        }
    }

    private static UInt32 GetBrowserEmulationMode()
    {
        int browserVersion = 7;
        using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftInternet Explorer",
            RegistryKeyPermissionCheck.ReadSubTree,
            System.Security.AccessControl.RegistryRights.QueryValues))
        {
            var version = ieKey.GetValue("svcVersion");
            if (null == version)
            {
                version = ieKey.GetValue("Version");
                if (null == version)
                    throw new ApplicationException("Microsoft Internet Explorer is required!");
            }
            int.TryParse(version.ToString().Split('.')[0], out browserVersion);
        }

        // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
        UInt32 mode = 10000;

        switch (browserVersion)
        {
            case 7:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                mode = 7000;
                break;
            case 8:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                mode = 8000;
                break;
            case 9:
                // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                mode = 9000;
                break;
            default:
                // use IE10 mode by default
                break;
        }

        return mode;
    }
}

}

Just instantiated this class and fed it my webbrowser control:

WebBroweerControls.Form1 f1 = new WebBroweerControls.Form1(this.webBrowser1);

 

 

————————————————-

Answer

Try the following…

 var html = "<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" " +
                   "src="https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
                   "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
                   "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed">" +
                   "</iframe>" +
                   "<br /><small><a href="https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
                   "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
                   "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7" style="color:#0000FF;" +
                   "text-align:left">View Larger Map</a></small>";

 webBrowser1.NavigateToString(html);

Basically the same code… Just used NavigateToString() to load the html parameter to WebBrowser.

c++,webbrowser-control,wpf

Facebook Comments

Post a comment