there is a way to activate a control WebView Desktop mode and not Mobile mode?

ε祈祈猫儿з 提交于 2019-12-09 14:53:43

问题


there is a way to activate a control WebView Desktop mode and not Mobile mode?

<WebView x:name= "WebViewApp" ..../>

回答1:


The WebView doesn't have an inherent desktop or mobile mode. Whether a site provides a mobile or desktop optimised site is generally based on the User Agent header. You can set this in a WebView by creating an HttpWebRequest with the agent you want and then navigating with WebView.NavigateWithHttpRequestMessage.

If you want to mimic a specific browser mode you can find the user agent it uses at several web sites.

string userAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop) like Gecko"
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(
    HttpMethod.Post, new Uri("http://whatsmyuseragent.com"));
httpRequestMessage.Headers.Append("User-Agent",userAgent);

myWebView.NavigateWithHttpRequestMessage(httpRequestMessage);



回答2:


You can try adding a viewport meta tag with a "desktop" width to your <head>, like:

<meta name="viewport" content="width=1024">

or

<meta name="viewport" content="width=1024,initial-scale=1, maximum-scale=1, user-scalable=no">

Try this in order to set your user agent:~

webView.SetWebViewClient (new MyWebViewClient());

// ...

public class MyWebViewClient : WebViewClient
{
    public override bool ShouldOverrideUrlLoading(WebView view, string url)
    {
        view.Settings.UserAgentString = "your-user-agent-here";
        view.LoadUrl(url);
        return true;
    }
}



来源:https://stackoverflow.com/questions/28549929/there-is-a-way-to-activate-a-control-webview-desktop-mode-and-not-mobile-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!