Winform Webbrowser being recognized as a mobile de

2019-07-20 02:42发布

问题:

I'm trying to open websites through the web browser control inside winforms. Although whatever websites it does open, it opens through the mobile version. My web browser is being recognizeed as a mobile device.

回答1:

You can navigate to the page using Navigate method and pass a suitable User-Agent string as additionalHeaders parameter.

The trick is useful for sites which detect mobile mode at server-side based on user-agent string. For some sites which doesn't detect mobile mode and only have client-side responsive design which is based on browser size, you can resize the browser control to a suitable size to show mobile view.

Example

Here is an example of user agent string of Galaxy Nexus:

this.webBrowser1.Navigate("http://www.stackoverflow.com",
                          null,
                          null,
                          "User-Agent:Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19");

As result you see stackoverflow site in mobile mode: