How to determine whether user is on a mobile device from a plugin?

Posted: January 12, 2018 at 10:29 PM Quote #199156
Is there a way to determine, from a plug-in, if a visitor/user is on a mobile device or not in NopCommerce (any version from 3.1 and up)?
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: January 13, 2018 at 7:36 AM Quote #199162
To detect ..what app the client is using you can use simple codes on either client side or server side..

if you want to detect the browser with JavaScript  .. The following code should do ...also an working example


// keep adding all useragents for mobile browsers
var isChromium = window.chrome,
    winNav = window.navigator,
    vendorName = winNav.vendor,
    isOpera = winNav.userAgent.indexOf("OPR") > -1,
    isIEedge = winNav.userAgent.indexOf("Edge") > -1,
    isIOSChrome = winNav.userAgent.match("CriOS");

if(isIOSChrome){
   console.log('is Google Chrome on IOS');
   alert('is Google Chrome on IOS');
} else if(isChromium !== null && isChromium !== undefined && vendorName === "Google Inc." && isOpera == false && isIEedge == false) {
  console.log('is Google Chrome');
  alert('is Google Chrome');
} else {
   console.log('not Google Chrome');
   alert('not Google Chrome');
}



and in case you want to detect the browser from your plugin c#...

System.Web.HttpBrowserCapabilities browser = Request.Browser;
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
https://stackoverflow.com/users/4588302/raja-ji
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2018
Learn more