ControlAdapter.Browser 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得對用戶端瀏覽器功能的參考 (此用戶端是發出目前 HTTP 要求的用戶端)。
protected:
property System::Web::HttpBrowserCapabilities ^ Browser { System::Web::HttpBrowserCapabilities ^ get(); };
protected System.Web.HttpBrowserCapabilities Browser { get; }
member this.Browser : System.Web.HttpBrowserCapabilities
Protected ReadOnly Property Browser As HttpBrowserCapabilities
屬性值
HttpBrowserCapabilities,指定用戶端瀏覽器和標記功能。
範例
下列程式碼範例示範如何使用 Browser 屬性來存取要求瀏覽器的詳細資料。 在此範例中,程式碼會檢查以判斷瀏覽器是否與 JavaScript 相容,然後允許開發人員在該情況下轉譯自訂輸出。
#using <System.Web.dll>
#using <System.dll>
using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::Adapters;
public ref class CustomControlAdapter: public ControlAdapter
{
protected:
virtual void Render( HtmlTextWriter^ writer ) override
{
// Access Browser details through the Browser property.
Version^ jScriptVersion = Browser->JScriptVersion;
// Test if the browser supports Javascript.
if ( jScriptVersion != nullptr )
{
// Render JavaScript-aware markup.
}
else
{
// Render scriptless markup.
}
}
};
using System;
using System.Web.UI;
using System.Web.UI.Adapters;
public class CustomControlAdapter : ControlAdapter
{
protected override void Render( HtmlTextWriter writer )
{
// Access Browser details through the Browser property.
Version jScriptVersion = Browser.JScriptVersion;
// Test if the browser supports Javascript.
if (jScriptVersion != null)
{
// Render JavaScript-aware markup.
}
else
{
// Render scriptless markup.
}
}
}
Imports System.Web.UI
Imports System.Web.UI.Adapters
Public Class CustomControlAdapter
Inherits ControlAdapter
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
' Access Browser details through the Browser property.
Dim jScriptVersion As Version = Browser.jScriptVersion
' Test if the browser supports Javascript.
If Not (jScriptVersion Is Nothing) Then
' Render JavaScript-aware markup.
Else
' Render scriptless markup.
End If
End Sub
End Class
備註
ControlAdapter物件會從 HttpBrowserCapabilities 屬性所 Browser 傳回的物件判斷用戶端瀏覽器功能。 這可讓 ControlAdapter 物件轉譯瀏覽器特定的標記,或修改 的行為 Control 。