Microsoft Ajax library browser type judgment

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.