如何在JavaScript或Ruby Rails中检测来自桌面用户代理的请求?(How to detect a request coming from desktop user agent in JavaScript or Ruby Rails? [closed])

如何检测特定请求是否来自桌面?

我在JavaScript中试过这个解决方案:

function isDesktop(){ var isTouchDevice = function() { return window.screenX === 0 && 'ontouchstart' in window || 'onmsgesturechange' in window; }; var isDesktop = !isTouchDevice() ? true : false; } isDesktop();

它可以工作,但这仅适用于触摸和非触摸设备,而今天的一代有触摸笔记本电脑和屏幕。

任何人都可以建议一些解决方案,我们可以适当地检测桌面除了所有其他设备?

How can I detect if a particular request is coming from a desktop?

I've tried for this solution in JavaScript:

function isDesktop(){ var isTouchDevice = function() { return window.screenX === 0 && 'ontouchstart' in window || 'onmsgesturechange' in window; }; var isDesktop = !isTouchDevice() ? true : false; } isDesktop();

It works but this is applicable for only touch and non-touch devices, whereas today's generation have touch laptops and screens.

Can anyone suggest some solution where we can appropriately detect desktops apart from all other devices??

最满意答案

我在红宝石中找到了一个技巧,并且确实起了作用。 我使用browser gem来告诉你请求设计是“移动or平板电脑”。

我只是否定了响应并将其视为桌面,如果它不是移动设备而不是平板设备。

有关更多说明,请参阅安装gem后的代码段。 这是参考

需要“浏览器”

browser = Browser.new(:ua => request.user_agent,:accept_language =>“en-us”) if!browser.mobile? &&!browser.tablet? @device =“桌面” 结束

I've found a trick in ruby and that did its work. Am using browser gem which tells you whether the request devise is 'mobileortablet`.

Am just negating the response and considering it as desktop if its not a mobile device and not a tablet device.

For more clarification here is the code snippet after installing the gem. here is the reference

require "browser"

browser = Browser.new(:ua => request.user_agent, :accept_language => "en-us") if !browser.mobile? && !browser.tablet? @device = "desktop" end

如何在JavaScript或Ruby Rails中检测来自桌面用户代理的请求?(How to detect a request coming from desktop user agent in JavaScript or Ruby Rails? [closed])

如何检测特定请求是否来自桌面?

我在JavaScript中试过这个解决方案:

function isDesktop(){ var isTouchDevice = function() { return window.screenX === 0 && 'ontouchstart' in window || 'onmsgesturechange' in window; }; var isDesktop = !isTouchDevice() ? true : false; } isDesktop();

它可以工作,但这仅适用于触摸和非触摸设备,而今天的一代有触摸笔记本电脑和屏幕。

任何人都可以建议一些解决方案,我们可以适当地检测桌面除了所有其他设备?

How can I detect if a particular request is coming from a desktop?

I've tried for this solution in JavaScript:

function isDesktop(){ var isTouchDevice = function() { return window.screenX === 0 && 'ontouchstart' in window || 'onmsgesturechange' in window; }; var isDesktop = !isTouchDevice() ? true : false; } isDesktop();

It works but this is applicable for only touch and non-touch devices, whereas today's generation have touch laptops and screens.

Can anyone suggest some solution where we can appropriately detect desktops apart from all other devices??

最满意答案

我在红宝石中找到了一个技巧,并且确实起了作用。 我使用browser gem来告诉你请求设计是“移动or平板电脑”。

我只是否定了响应并将其视为桌面,如果它不是移动设备而不是平板设备。

有关更多说明,请参阅安装gem后的代码段。 这是参考

需要“浏览器”

browser = Browser.new(:ua => request.user_agent,:accept_language =>“en-us”) if!browser.mobile? &&!browser.tablet? @device =“桌面” 结束

I've found a trick in ruby and that did its work. Am using browser gem which tells you whether the request devise is 'mobileortablet`.

Am just negating the response and considering it as desktop if its not a mobile device and not a tablet device.

For more clarification here is the code snippet after installing the gem. here is the reference

require "browser"

browser = Browser.new(:ua => request.user_agent, :accept_language => "en-us") if !browser.mobile? && !browser.tablet? @device = "desktop" end