前言:Silverlight 2.0 Beta1 已经发布,加入了许多激动人心的新特性:WPF UI 框架、丰富的控件、丰富的网络支持、丰富的基础类库支持等。这是本人的学习笔记,写的比较乱,因此定名为乱弹琴 Silverlight 2.0 系列文章。

本篇介绍如何获得浏览器信息。

Silverlight 2.0 中,System.Windows.Browser是用语于处理与HTML交互的命名空间。
有以下类型:
BrowserInformation
HtmlDocument
HtmlElement
HtmlElementCollection
HtmlEventArgs
HtmlObject
HtmlPage
HtmlWindow
HttpUtility
ScriptableMemberAttribute
ScriptableTypeAttribute
ScriptObject

BrowserInformation:
是密封类,不能派生子类,无公共的构造函数。他的属性只能从HtmlPage的静态属性BrowserInformation取得。
主要有以下属性:
BrowserVersion
CookiesEnabled
Name
Platform
UserAgent

示例:
XAML:
<StackPanel Background="DarkGreen">
    
<TextBlock x:Name="bn" Style="{StaticResource txt}"></TextBlock>
    
<TextBlock x:Name="bv" Style="{StaticResource txt}"></TextBlock>
    
<TextBlock x:Name="ba" Style="{StaticResource txt}"></TextBlock>
    
<TextBlock x:Name="bc" Style="{StaticResource txt}"></TextBlock>
    
<TextBlock x:Name="bp" Style="{StaticResource txt}"></TextBlock>
</StackPanel>

C#:
BrowserInformation b = HtmlPage.BrowserInformation;
bn.Text
= string.Format("Name:\n {0}", b.Name);
bv.Text
= string.Format("BrowserVersion:\n {0}", b.BrowserVersion);
bc.Text
= string.Format("CookiesEnabled:\n {0}", b.CookiesEnabled);
ba.Text
= string.Format("UserAgent:\n {0}", b.UserAgent);
bp.Text
= string.Format("Platform:\n {0}", b.Platform);

运行效果:
FF:
乱弹琴 Silverlight 2.0 (7) 获取浏览器信息
IE:
乱弹琴 Silverlight 2.0 (7) 获取浏览器信息

结束语:

BrowserInformation区别与浏览器相关的操作有一定的意义,如兼容性,是否禁用Cookies等。

下一篇介绍Silverlight与HTML Dom互操作。

相关文章:

  • 2021-08-03
  • 2022-02-27
  • 2022-01-19
  • 2022-02-18
  • 2021-12-29
  • 2021-08-31
  • 2022-01-15
  • 2022-01-27
猜你喜欢
  • 2021-10-17
  • 2021-12-02
  • 2021-11-20
  • 2021-11-16
  • 2022-01-22
  • 2021-08-14
  • 2021-11-10
相关资源
相似解决方案