Welcome to MSDN Blogs Sign in | Join | Help

News

  • These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified Terms of Use
Tip #13: Did you know... How to get the browser agent using ASP.NET Ajax ?

When writing JavaScript for a web application, there may be times when you want to do something different depending on the browser that is requesting the page. ASP.NET Ajax has an easy way to this with the Sys.Browser object.

For example, let's say you want to do something different if the requesting browser is Opera. The code snippet below shows how to do that:

<script language="javascript" type="text/javascript">
function DoSomething() {
    if(Sys.Browser.agent === Sys.Browser.Opera)
    {
        // opera specific code here
    }
}
</script>

There are other useful properties of the Browser object. For example, Sys.Browser.version.toString(); will return the version of the browser, if you need further granularity when deciding what to do for each browser version.

Federico Silva Armas
SDET, ASP.NET QA Team

Posted: Friday, October 10, 2008 9:40 AM by WebDevTools

Comments

Visual Web Developer Team Blog said:

Here are four new tips on Tips and Trick Blog. Tip #10 Did you know… Visual Web Developer 2008 has a

# October 10, 2008 7:48 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker