不過資料都收集了,就稍加整理做為這次被考驗的紀念...
-----------------------------------這是分隔線-----------------------------------
偵測用戶端瀏覽器屬性在前端可以用javascript達成,例如:
alert(navigator.userAgent);
有時必須在後端做判斷,(ASP.NET WebForm)可以取 Requset.UserAgent的值,
更細節的支援功能則可使用HttpRequest.Browser
How to: Detect Browser Types and Browser Capabilities in ASP.NET Web Forms
必須注意的是HttpBrowserCapabilities 提供的是用戶端瀏覽器所支援的功能,而不是用戶端瀏覽器的設定值。
想要將用戶端瀏覽器支援的功能呈現在網頁上,MSDN提供的範例是:
HttpBrowserCapabilities bc = Request.Browser;
Response.Write("<p>Browser Capabilities:</p>");
Response.Write("Type = " + bc.Type + "<br>");
Response.Write("Name = " + bc.Browser + "<br>");
Response.Write("Version = " + bc.Version + "<br>");
Response.Write("Major Version = " + bc.MajorVersion + "<br>");
Response.Write("Minor Version = " + bc.MinorVersion + "<br>");
Response.Write("Platform = " + bc.Platform + "<br>");
Response.Write("Is Beta = " + bc.Beta + "<br>");
Response.Write("Is Crawler = " + bc.Crawler + "<br>");
Response.Write("Is AOL = " + bc.AOL + "<br>");
Response.Write("Is Win16 = " + bc.Win16 + "<br>");
Response.Write("Is Win32 = " + bc.Win32 + "<br>");
Response.Write("Supports Frames = " + bc.Frames + "<br>");
Response.Write("Supports Tables = " + bc.Tables + "<br>");
Response.Write("Supports Cookies = " + bc.Cookies + "<br>");
Response.Write("Supports VB Script = " + bc.VBScript + "<br>");
Response.Write("Supports JavaScript = " + bc.JavaScript + "<br>");
Response.Write("Supports Java Applets = " + bc.JavaApplets + "<br>");
Response.Write("Supports ActiveX Controls = " + bc.ActiveXControls + "<br>");
Response.Write("CDF = " + bc.CDF + "<br>");
將該範例稍做修改列出支援的全部功能:
HttpBrowserCapabilities bc = Request.Browser; Response.Write("Browser Capabilities:"); foreach(string k in bc.Capabilities.Keys) { Response.Write(k + " = " + bc.Capabilities[k] + "<br>"); } Response.Write("user agent = " + Request.UserAgent);
沒有留言:
張貼留言