You would detect the requesting browsers user agent string, and then decide based on what it is if it's coming from a mobile browser or not. This device is not perfect, and never will be due to the fact that user agents aren't standardized for mobile devices (at least not to my knowledge).
This site will help you create the code: http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
Example:
You could get the user agent in javascript by doing this:
var uagent = navigator.userAgent.toLowerCase();
And then do the check's in the same format as this (just using iPhone as a quick example, but others would need to be a little bit different)
function DetectIphone()
{
if (uagent.search("iphone") > -1)
alert('true');
else
alert('false');
}
Edit
You'd create a simple HTML page like so:
<html>
<head>
<title>Mobile Detection</title>
</head>
<body>
<input type="button" OnClick="DetectIphone()" value="Am I an Iphone?" />
</body>
</html>
<script>
function DetectIphone()
{
var uagent = navigator.userAgent.toLowerCase();
if (uagent.search("iphone") > -1)
alert('true');
else
alert('false');
}
</script>