You can use:
1) JS: Detect by user agent
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
Take the user agent strings from here:
http://www.useragentstring.com/pages/useragentstring.php.
2) CSS: Use responsive design
3) JS: Detect the screen width by screen.width