RazorSPoint

How to set the WebBrowser Controll to show mobile pages

Sebastian SchützeSebastian Schütze

Did you notice that when you go to the settings oft he Internet Explorer that you can choose if you want a web page to be rendere das a mobile webpage or a desktop web page? This is pretty good because you the resolution oft he windows phones is actually good enough to not show just low resolution websites. But depending on the data that is transfered and the loading speed you maybe want to just see the mobile version of a web page (if available). But what if I want to use the WebBrowser Control in my Windows Phone Application? I have no Settings at all. I can’t even use different Tabs in my Control. This Control ist just giving me the possibility to display web pages in the internet of html files which I have on my phone. Furthermore when you want to display web pages and the web page automatically recognizes your mobile phone then it displays the mobile version of the web page. Maybe you don’t want that. But to easily work around that (or even duplicate the settings in the IE app) you just need to send additional headers to the server. You just say the server “hey I am not a mobile phone and don’t want to have the mobile version. I am a desktop computer”. This means you can actually send header that you are a “Mozilla” even if you are not. The Header you need to send are the following:

Now when it comes to sending the header in you control just do the following thing:

private void HyperlinkButton_Click(object sender, RoutedEventArgs e)

{

// this is a property in my ViewModel which looks i fit should be desktop or mobile version

if (App.ViewModel.Settings.IsMobileVersion)

{

webBrowser.Navigate(new Uri("http://www.mirosoft.com"), null, "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; HTC; T8788)");

}

else

{

webBrowser.Navigate(new Uri("http://www.mirosoft.com"), null, "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7; ZuneWP7)");

}

}

If you want to get some more Information about sending header in Silverlight just go to the msdn library

Sebastian is an Azure Nerd with focus on DevOps and Azure DevOps (formerly VSTS) that converted from the big world of SharePoint and O365. He was working with O365 since 2013 and loved it ever since. As his focus shifted in 2017 to more DevOps related topics in the Microsoft Stack. He learned to love the possibilities of automation. Besides writing articles in his blog and German magazines, he is still contributing to the SharePoint Developer Community (and PnP SharePoint) to help to make the ALM part a smoother place to live in.

Comments 8
  • prog1
    Posted on

    prog1 prog1

    Reply Author

    Does not work. Semms to be something wrong with the code snippet.
    For Navigate method I need a Uri object.


    • Sebastian Schütze
      Posted on

      Sebastian Schütze Sebastian Schütze

      Reply Author

      Thank you I corrected the code snippet and it should work now, I mixed it up with something else and of course you are right. A Uri object is needed for this.

      You can use the snippet now and it should work!


      • prog1
        Posted on

        prog1 prog1

        Reply Author

        No sorry, still not working. The Uri needs something like this:

        browser.Navigate(new Uri(“http://www.microsoft.com”), null, “Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7; ZuneWP7)”);)”);

        But if there is no exception it does not work anyway. I’m using the emulator, could this be the problem?


        • Sebastian Schütze
          Posted on

          Sebastian Schütze Sebastian Schütze

          Reply Author

          Yes this is a copy and paste error by me. I fogort something really important. You need to tell of course what kind of header you want to send:

          Just correct to this for the header:

          User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7; ZuneWP7)

          (the other header as well!


          • prog1
            Posted on

            prog1 prog1

            Author

            Great work!!! Thanks a lot!


  • MB
    Posted on

    MB MB

    Reply Author

    Does this also work for WP8 .. or should i need to change the strings to WP8, IEMobile8 etc…


This site uses Akismet to reduce spam. Learn how your comment data is processed.