Win10 how the UWP lets WebView identify Win10 phone

Source: Internet
Author: User
Tags creative commons attribution blank page

This article main: How to let WebView visit page set not for mobile phone, of course, this sentence I say not good, change, how to let WebView set not for mobile phone. The above two sentences are wrong, because it is the server identification, not the Web page, the second sentence should be to let the server instead of WebView. Why this is written because there is a great God in the group to ask this, he said so, I write so I hope you can see in the search. Of course this article in Csdn and Win10.me, in his place did not send, but my gitbook.io still have.

How to let WebView set the phone, in fact, very simple, but I did not find WebView useragent actually found that he does not need.

We're at the front desk

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">        <WebView x:Name="Webview"/>        <Button Content="手机" Click="WebPhone_OnClick"/>    </Grid>

And it's easy in the background.

Because we need to use httprequestmessage, he can have httpRequestMessage.Headers.Add("User-Agent", userAgent); so we find Webview.navigatewithhttprequestmessage

I write these buttons.

private void Webphone_onclick (object sender, RoutedEventArgs e) {var httprequestmessage = new Windows. Web. Http. Httprequestmessage(Windows. Web. Http. HttpMethod. Get, New Uri (URL));var useragent ="mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; webview/3.0; Microsoft; Virtual) applewebkit/537.36 (khtml, like Gecko) chrome/42.0.2311.135 Mobile safari/537.36 edge/12.10240 sample/1.0 " ;Httprequestmessage. Headers. ADD("User-agent", useragent);Webview. Navigatewithhttprequestmessage(Httprequestmessage);}

Over here

var"Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; WebView/3.0; Microsoft; Virtual) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10240 sample/1.0";

Can be modified, see Http://outofmemory.cn/code-snippet/1901/mobile-liulanqi-User-Agent-summary

All code

usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Runtime.InteropServices.WindowsRuntime;usingWindows.foundation;usingWindows.Foundation.Collections;usingWindows.UI.Xaml;usingWindows.UI.Xaml.Controls;usingWindows.UI.Xaml.Controls.Primitives;usingWindows.UI.Xaml.Data;usingWindows.UI.Xaml.Input;usingWindows.UI.Xaml.Media;usingWindows.UI.Xaml.Navigation;//"Blank page" item template is described on http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409Namespace webviewuwp{//   <summary>       ///can be used for itself or to navigate to a blank page inside the Frame.     //   </summary>      Public Sealed Partial classMainpage:page { Public MainPage()        { This.            InitializeComponent (); Webview.navigate (NewUri (URL)); }Private stringURL {Set;Get; }        ="HTTP://BLOG.CSDN.NET/LINDEXI_GD";Private void Webphone_onclick(Objectsender, RoutedEventArgs e) {varHttprequestmessage =NewWindows.Web.Http.HttpRequestMessage (Windows.Web.Http.HttpMethod.Get,NewUri (URL));varUserAgent ="mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; webview/3.0; Microsoft; Virtual) applewebkit/537.36 (khtml, like Gecko) chrome/42.0.2311.135 Mobile safari/537.36 edge/12.10240 sample/1.0 " ; HTTPREQUESTMESSAGE.HEADERS.ADD ("User-agent", useragent);        Webview.navigatewithhttprequestmessage (Httprequestmessage); }    }}

If you do not understand the basics, see: http://blog.csdn.net/lindexi_gd/article/details/52041944


This work is licensed under the Creative Commons Attribution-NonCommercial use-Share 4.0 International license agreement in the same way. Welcome to reprint, use, republish, but be sure to keep the article Attribution Lindesi (including Link: http://blog.csdn.net/lindexi_gd), not for commercial purposes, based on the modified works of this article must be issued with the same license. If you have any questions, please contact me.

Win10 how the UWP lets WebView identify Win10 phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.