This javascript allows you to detect if a visitor going to your website is using a mobile device. If they are you could redirect them to the mobile version of your website. While this detection/redirection process is best served executed by a server-side script, I've provided the detection in javascript form.
Source Code:
<script type="text/javascript" language="javascript">
window.onload = function() { checkMobileDevice(); }
function checkMobileDevice() {
var current_browserDetect = navigator.userAgent.toLowerCase();
var current_browserName = "";
if (current_browserDetect.toLowerCase().indexOf("samsung") > 0 && current_browserDetect.toLowerCase().indexOf("netfront") > 0) { /* Samsung T-Mobile */ current_browserName = "Samsung T-Mobile"; }
else if (current_browserDetect.toLowerCase().indexOf("mozilla") > 0 && current_browserDetect.toLowerCase().indexOf("openweb") > 0) { /* LG RUMOR */ current_browserName = "LG RUMOR"; }
else if (current_browserDetect.toLowerCase().indexOf("ipod") > 0 || current_browserDetect.toLowerCase().indexOf("iphone") > 0) { /* Iphone or Ipod Touch */ current_browserName = "Iphone or Ipod Touch"; }
else if (current_browserDetect.toLowerCase().indexOf("android") > 0) { /* Motorola Droid or Droid Eris */ current_browserName = "Motorola Droid or Droid Eris"; }
else if (current_browserDetect.toLowerCase().indexOf("blackberry") > 0) { /* blackberry */ current_browserName = "Blackberry"; }
/* Mobile Device Detected */
if (current_browserName.length > 0) { alert("Mobile Device Detected:\n\n" + current_browserName); }
}
</script>