> 
> **Possible Duplicate:**  
> 
> [What is the Best way to do Browser Detection in Javascript?](https://stackoverflow.com/questions/588940/what-is-the-best-way-to-do-browser-detection-in-javascript) 
> 
> 
> 

I'd like to essentially do the following (in JavaScript or PHP):

```
if (desktop browser) {
     do x;
}
else {   // mobile browser
     do not do x;
}

```

It is known that using a browser [detection method is not recommended](http://css-tricks.com/browser-detection-is-bad/). A better solution is using a [capability testing](http://quirksmode.org/js/support.html). My question is, with mobile browsers become smarter and as powerful as the desktop version, what ideally exclusive capability detection to filter the desktop from non-desktop browsers?

I think reversing the conditional check i.e. `if (mobile browser) {} else ...` might prove to be more problematic, right?