共用方式為


BrowserInformation Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides general information about the browser, such as name, version, and operating system.

Inheritance Hierarchy

System.Object
  System.Windows.Browser.BrowserInformation

Namespace:  System.Windows.Browser
Assembly:  System.Windows.Browser (in System.Windows.Browser.dll)

Syntax

'Declaration
Public NotInheritable Class BrowserInformation
public sealed class BrowserInformation

The BrowserInformation type exposes the following members.

Properties

  Name Description
Public property BrowserVersion Gets the version of the browser technology that the current browser is based on.
Public property CookiesEnabled Gets a value that indicates whether the browser supports cookies.
Public property Name Gets the name of the browser technology that the current browser is based on.
Public property Platform Gets the name of the browser operating system.
Public property ProductName Gets the product name of the browser.
Public property ProductVersion Gets the product version number of the browser.
Public property UserAgent Gets the user agent string of the browser.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

This class corresponds to the Navigator object of the browser. It is accessed through the HtmlPage class.

The following table lists Silverlight BrowserInformation members and their corresponding JavaScript functions.

BrowserInformation property

JavaScript function

Name

Navigator.appName

BrowserVersion

Navigator.appVersion

UserAgent

Navigator.userAgent

Platform

Navigator.platform

CookiesEnabled

Navigator.cookieEnabled

ProductName and ProductVersion

Values are extracted from Navigator.userAgent

Examples

The following example demonstrates how the BrowserInformation class provides browser information.

Imports System
Imports System.Windows.Controls
Imports System.Windows.Browser

Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      outputBlock.Text += vbCrLf
      outputBlock.Text += "Silverlight can provide browser information:" & vbCrLf
      outputBlock.Text += "Browser Name = " & HtmlPage.BrowserInformation.Name & vbCrLf
      outputBlock.Text += "Browser Version = " & HtmlPage.BrowserInformation.BrowserVersion.ToString() & vbCrLf
      outputBlock.Text += "UserAgent = " & HtmlPage.BrowserInformation.UserAgent & vbCrLf
      outputBlock.Text += "Platform = " & HtmlPage.BrowserInformation.Platform & vbCrLf
      outputBlock.Text += "CookiesEnabled = " & HtmlPage.BrowserInformation.CookiesEnabled.ToString() & vbCrLf
      outputBlock.Text += "ProductName = " & HtmlPage.BrowserInformation.ProductName.ToString() & vbCrLf
      outputBlock.Text += "ProductVersion = " + HtmlPage.BrowserInformation.ProductVersion.ToString()

   End Sub 'Main
End Class 'Sample
using System;
using System.Windows.Controls;
using System.Windows.Browser;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
     outputBlock.Text +=
       "\nSilverlight can provide browser information:\n" +
       "\nBrowser Name = " + HtmlPage.BrowserInformation.Name +
       "\nBrowser Version = " + HtmlPage.BrowserInformation.BrowserVersion.ToString() +
       "\nUserAgent = " + HtmlPage.BrowserInformation.UserAgent +
       "\nPlatform = " + HtmlPage.BrowserInformation.Platform +
       "\nCookiesEnabled = " + HtmlPage.BrowserInformation.CookiesEnabled.ToString() +
       "\nProductName = " + HtmlPage.BrowserInformation.ProductName.ToString() +
       "\nProductVersion = " + HtmlPage.BrowserInformation.ProductVersion.ToString();
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.