1

I am creating a website with node.js, which I will make a mobile app. The app will just open the website, and app users can use it from there. However, I would like to detect if the site is accessed on a PC. If it is detected on a PC, I will show a page that gives the user a link to the app on the app store for example. How can I detect if my site is being accessed from a PC? Thanks!

dec0mpiled
  • 99
  • 1
  • 14
  • it's usually made through server checking user agent – juvian Mar 03 '16 at 01:06
  • So if they are browsing on a PC, you want to show them a link to install the app that they can't install on their PC? Do you mean instead that you want to detect if they are accessing the site on a mobile, but not via the app? – GregL Mar 03 '16 at 01:15
  • We are talking about the Android app or iOS app? – stdob-- Mar 03 '16 at 01:22
  • In other words, you need to determine - if the link from the mobile application then show's website, if any browser (including from mobile) - show a link to the store. – stdob-- Mar 03 '16 at 01:24

4 Answers4

1

By User Agent:

console.log(navigator.userAgent);

Or by screen size:

console.log(screen.height);
console.log(screen.width);
Fabius
  • 506
  • 9
  • 22
1

This one - navigator.userAgentData is an object with 3 attributes:

  • the brand of the user
  • the platform of the user
  • if the user is on mobile

you can use this one navigator.userAgentData.mobile to check if the user is on mobile. If he is not on a mobile, then most likely he is on a PC.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Adam
  • 89
  • 1
  • 9
0

Check out this link:

HTML5: Detecting if you're on mobile or pc with javascript?

You can either check by reading the screen width and checking to see if it's < a particular size or use User Agent Detection

Community
  • 1
  • 1
James111
  • 15,378
  • 15
  • 78
  • 121
0

By experience I find the most accurate and easy way to do it is by using media queries, adding a DIV for each one of the options (mobile and PC), hide them in the CSS file based on the one being used, and that always work with no compatibility issues and browser independent.

To know more about media queries, please check: http://www.w3schools.com/css/css_rwd_mediaqueries.asp

goncalopinto
  • 433
  • 2
  • 8