Can I securely restrict access to desktop users on my mobile site?

This question already has an answer here:

  • What is the best way to detect a mobile device in jQuery? 49 answers

  • 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检测是否移动并设置条件

    下一篇: 我可以安全地限制访问我的移动网站上的桌面用户吗?