Microsoft ASP. NET Ajax has a browser compatibility layer, which provides browser compatibility and supports the same encoding method and Code Implement the same functions in different browsers.
In the ASP. NET Ajax framework, you can use the SYS. browser attribute to obtain the browser type:
1) SYS. browser. Agent-browser type, which has the following four values:
SYS. browser. internetexplorer
SYS. browser. Firefox
SYS. browser. Safari
SYS. browser. Opera
2) SYS. browser. Name -- Name of the browser
Microsoft Internet Explorer
Firefox
Safari
Opera -- display of the name has not been tested in this Browser
3) SYS. browser. version -- version of the browser
Detection example <% @ Page Language="C #" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Browser Detection example </ Title >
< Script Language = "JavaScript" Type = "Text/JavaScript" SRC = "Microsoftajax. js" > </ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Script Type = "Text/JavaScript" >
<! --
Function Pageload (sender, E) {
VaR Browser = String. Format ( " Your browser is {0} {1} " , SYS. browser. Name, SYS. browser. version );
Alert (browser );
If (SYS. browser. Agent = SYS. browser. internetexplorer) {
Alert ('This message is displayed only on Internet Explorer!');
}
}
// -->
</ Script >
</ Form >
</ Body >
</ Html >
The code for implementing this function in the Microsoft Ajax library script library is as follows: SYS. Browser = {} ;
SYS. browser. internetexplorer = {} ;
SYS. browser. Firefox = {} ;
SYS. browser. Safari = {} ;
SYS. browser. Opera = {} ;
SYS. browser. Agent = Null ;
SYS. browser. hasdebuggerstatement = False ;
SYS. browser. Name = Navigator. appname;
SYS. browser. Version = Parsefloat (navigator. appversion );
If (Navigator. useragent. indexof ( ' MSIE ' ) > - 1 ) {< br> sys. browser. agent = sys. browser. internetexplorer;
sys. browser. version = parsefloat (navigator. useragent. match ( / MSIE (\ D + \. \ D +) / ) [ 1 ]);
sys. browser. hasdebuggerstatement = true ;< BR >}
Else If (Navigator. useragent. indexof ( ' Firefox/ ' ) > - 1 ) {
SYS. browser. Agent = SYS. browser. Firefox;
SYS. browser. Version = Parsefloat (navigator. useragent. Match ( / Firefox \ / (\ D + \. \ D +) / )[ 1 ]);
SYS. browser. Name = ' Firefox ' ;
SYS. browser. hasdebuggerstatement = True ;
}
Else If (Navigator. useragent. indexof ( ' Safari/ ' ) > - 1 ) {
SYS. browser. Agent = SYS. browser. Safari;
SYS. browser. Version = Parsefloat (navigator. useragent. Match ( / Safari \ / (\ D + (\. \ D + )?) / )[ 1 ]);
SYS. browser. Name = ' Safari ' ;
}
Else If (Navigator. useragent. indexof ( ' Opera/ ' ) > - 1 ) {
SYS. browser. Agent=SYS. browser. Opera;
}
From the implementation code in the above script library, if the client browser is not the four mainstream browsers listed above, sys cannot be used. browser. agent, but sys. browser. name and version.