There are several similar questions on SO. But, as also mentioned in Detecting a mobile browser, a great resource are the scripts published on detectmobilebrowsers.com.
Basically you check the user agent from the request and do you magic if, in your case, it doesn't identify itself as a mobile device.
Of course, using any client-side script like Javascript or jQuery isn't really failsafe, as you've probably figured out. User agents, as provided through the header in a request, can be spoofed. The server-side scripts can provide you with additional sanity checks, but also they aren't even close to being "impossible to bypass".