我有一个网页,正在尝试检测用户是在桌面上还是在移动设备上访问该页面。执行此操作的典型方法是什么?注意我不想想要使用页面宽度(例如window.innerWidth<= 767) to check as the user may simply have resized the desktop. Can someone assist in the best way to achieve this?
谢谢!
为此目的规划的机制是 HTTP 标头中的 User-Agent 字段。 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent 但考虑一下 https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent 您可以在其中找到用于测试特定功能的 JavaScript 示例。
如果您想与客户进行测试,请查看 https://whatmyuseragent.com/
你好,xg