DO NOT USE USERAGENT.
Seriously. No. Not just. Pass away.
If you go this route, you will only ensure that the day you launch a new browser, or when one of the current mobile browsers changes its user agent value, your site will stay all broken for a lot of people. I've seen this happen before.
There are two elegant ways to know whether you should serve a mobile version of your site or not.
Check the screen size at hand. Like this:
if (screen.width < 640 || screen.height < 480) {
// sirva a versão pra celular
} else if (screen.width < 1024 || screen.height < 768) {
// talvez seja uma boa usar versão pra tablet
} else {
// sirva a versão normal
}
This form is for small, small cases, proof of concept perhaps. Note that this form may be dated in a few years: if your cell phones continue to tend to have higher screen resolution, this strategy will eventually stop working.
Use a library like Modernizr , which has a feature called "feature detection" . This is a much more elaborate way of knowing what the user's browser can understand and render. It goes beyond just determining the user device size factor. Based on what you get when using the Modernizr API you define whether and how some content will serve.
Take a look at the documentation.
You can also use Bootstrap to make styling easier. You can write a single HTML that fits automatically and looks great on your mobile, tablet, desktop, and big screen.
Edit: You say that you would like to improve the user experience by putting or removing buttons, etc.
Maybe what you're really interested in is whether your device has a touch screen, right? So you can serve an interface made to be touched if supported, and a clickable interface otherwise.
Many laptops nowadays have a touch screen. I have one with a very large screen and squeeze Windows and Chrome in it. Every website that uses the simple user agent is already broken by default for me.
The correct way to check this with Modernizr is:
var euDevoServirConteudoTouch = Modernizr.touch;
This is much more accurate than reading the user agent , so you know if the user will use a touch sensitive device regardless of whether the device is mobile.