Can I securely restrict access to desktop users on my mobile site?
This question already has an answer here:
There's no easy way to do this because there's no meaningful difference between a desktop browser and a mobile browser. User agents and screen sizes can easily be faked, of course, and Chrome's developer tools even have specific settings to emulate mobile browsers for testing, including emulating touch events and setting the device orientation (just click on the gear icon in the bottom-right).
Don't enforce this, because you will make a mistake and someone will be frustrated.
If you do, just use the user agent and hope nobody cares enough to bother.
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".
链接地址: http://www.djcxy.com/p/84056.html上一篇: JS检测是否移动并设置条件