2017-01-26
Visual Studio 2015 with Update 3
參考
偵測 Web Form 中的瀏覽器類型
https://msdn.microsoft.com/zh-tw/library/cc438041(v=vs.71).aspx
HOW TO:在 ASP.NET Web 網頁中偵測瀏覽器類型
https://msdn.microsoft.com/zh-tw/library/3yekbd5b(v=vs.100).aspx
Default.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Browser.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label_BrowserCapabilities" runat="server" Text=""></asp:Label> </div> </form> </body> </html> |
Default.aspx.cs
using System; namespace WebApplication2 { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { System.Web.HttpBrowserCapabilities browser = Request.Browser; string s = "Browser Capabilities<br /><br />" + "Type = " + browser.Type + "<br />" + "Name = " + browser.Browser + "<br />" + "Version = " + browser.Version + "<br />" + "Major Version = " + browser.MajorVersion + "<br />" + "Minor Version = " + browser.MinorVersion + "<br />" + "Platform = " + browser.Platform + "<br />" + "Is Beta = " + browser.Beta + "<br />" + "Is Crawler = " + browser.Crawler + "<br />" + "Is AOL = " + browser.AOL + "<br />" + "Is Win16 = " + browser.Win16 + "<br />" + "Is Win32 = " + browser.Win32 + "<br />" + "Supports Frames = " + browser.Frames + "<br />" + "Supports Tables = " + browser.Tables + "<br />" + "Supports Cookies = " + browser.Cookies + "<br />" + "Supports VBScript = " + browser.VBScript + "<br />" + "Supports JavaScript = " + browser.EcmaScriptVersion.ToString() + "<br />" + "Supports Java Applets = " + browser.JavaApplets + "<br />" + "Supports ActiveX Controls = " + browser.ActiveXControls + "<br />"; Label1.Text = s; } } } |
編譯有警告,先不理會
// 警告 CS0618 'HttpCapabilitiesBase.JavaScript' 已經過時: 'The recommended alternative is the EcmaScriptVersion property. A Major version value greater than or equal to 1 implies JavaScript support. http://go.microsoft.com/fwlink/?linkid=14202' Browser D:\CodeTemp\Browser\Browser\Default.aspx.cs 28 作用中
執行結果範例
//****************************************
Browser Capabilities
Type = InternetExplorer11
Name = InternetExplorer
Version = 11.0
Major Version = 11
Minor Version = 0
Platform = WinNT
Is Beta = False
Is Crawler = False
Is AOL = False
Is Win16 = False
Is Win32 = True
Supports Frames = True
Supports Tables = True
Supports Cookies = True
Supports VBScript = False
Supports JavaScript = 3.0
Supports Java Applets = False
Supports ActiveX Controls = False
****************************************
Browser Capabilities
Type = Chrome55
Name = Chrome
Version = 55.0
Major Version = 55
Minor Version = 0
Platform = WinNT
Is Beta = False
Is Crawler = False
Is AOL = False
Is Win16 = False
Is Win32 = True
Supports Frames = True
Supports Tables = True
Supports Cookies = True
Supports VBScript = False
Supports JavaScript = 3.0
Supports Java Applets = True
Supports ActiveX Controls = False
****************************************
Browser Capabilities
Type = Firefox51
Name = Firefox
Version = 51.0
Major Version = 51
Minor Version = 0
Platform = WinNT
Is Beta = False
Is Crawler = False
Is AOL = False
Is Win16 = False
Is Win32 = True
Supports Frames = True
Supports Tables = True
Supports Cookies = True
Supports VBScript = False
Supports JavaScript = 3.0
Supports Java Applets = True
Supports ActiveX Controls = False
****************************************
(完)
相關
[研究][C#][ASP.NET][WebForm] 偵測瀏覽器類型(二)
http://shaurong.blogspot.com/2017/03/caspnetwebform.html
[研究][C#][ASP.NET][WebForm] 偵測瀏覽器類型(一)
http://shaurong.blogspot.com/2017/01/caspnet.html
[研究] 檢查瀏覽器 JavaScript是否支援?是否啟用?
http://shaurong.blogspot.com/2016/01/aspnetc-javascript.html
http://shaurong.blogspot.com/2017/03/caspnetwebform.html
[研究][C#][ASP.NET][WebForm] 偵測瀏覽器類型(一)
http://shaurong.blogspot.com/2017/01/caspnet.html
[研究] 檢查瀏覽器 JavaScript是否支援?是否啟用?
http://shaurong.blogspot.com/2016/01/aspnetc-javascript.html
沒有留言:
張貼留言