Showing m.bing.com in the WP8 WebBrowser control

前端 未结 2 1085
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 17:25

I\'m having a problem getting bing.com to load in a WebBrowser control on Windows Phone 8. It seems that doing that will launch the WP8 Search App (same as pressing the Search

相关标签:
2条回答
  • 2021-01-24 18:08

    I don't have access to my emulator, but I tried it on my phone, and:

    1. The redirect doesn't happen when you "Prefer desktop version" and open m.bing.com. Warning: The mobile version isn't very pretty.

    2. Try disabling scripts on your WebBrowser, that could stop the redirect from happening.

    3. Any chance you could just use Google?

    0 讨论(0)
  • 2021-01-24 18:14

    I don't know if there's a better way to handle this, but I found a solution. I haven't gotten it to work perfectly when the back button is clicked, so I will update my answer if/when I found a more solid solution. I still think this is a big flaw in the WebBrowser control in WP8.

    Here is the code:

    private bool _customHeaderRequest = false;
    
    private void MainBrowser_Navigating(object sender, NavigatingEventArgs e)
    {
        string host = e.Uri.Host.ToLowerInvariant().Trim();
    
        if ((host == "bing.com" || host.EndsWith(".bing.com")) && !_customHeaderRequest)
        {
            e.Cancel = true;
    
            Dispatcher.BeginInvoke(() =>
                MainBrowser.Navigate(e.Uri, null,
                    "User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 710)\r\n"));
    
            _customHeaderRequest = true;
            return;
        }
    
        _customHeaderRequest = false;
    }
    
    private void MainBrowser_Navigated(object sender, NavigationEventArgs e)
    {
        _customHeaderRequest = false;
    }
    
    0 讨论(0)
提交回复
热议问题