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:
- For mobile version – “Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; HTC; T8788)”
- For desktop version – “Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7; ZuneWP7)”
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
prog1
Does not work. Semms to be something wrong with the code snippet.
For Navigate method I need a Uri object.
Sebastian Schütze
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
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
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
Great work!!! Thanks a lot!
MB
Does this also work for WP8 .. or should i need to change the strings to WP8, IEMobile8 etc…
Sebastian Schütze
Hi!
Here is an example of the user agent for WP8.
http://jonathanstark.com/blog/windows-phone-8-user-agent-string
MB
Thanks
Id does not work with query parameters
somehow the query params after the first & get dropped.
only the first one makes it thru