Warning: The following is never
the appropriate way to deal with browser differences. Instead of trying to sniff
the users browser to determine which document has the appropriate markup, code according to standards, use a standards doctype, and make good use of progressive-enhancement.
That being said, there are still various valid reasons for wishing to know which browser your user is currently using, and as such the following is how I would accomplish this for IE9 users.
Personally, I would encourage you to avoid browser sniffing as it's a very unreliable practice. Instead, use what native features the browser affords to you. In the case of Internet Explorer 9, you could use Conditional Comments:
<!--[if IE 9]>
alert("You appear to be using IE9");
Please note that Conditional Comments won't work after IE9 as IE10 dropped support for many of the non-standard features of the browser.
More on Conditional Comments here: msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx