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!
-
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 Answers
By User Agent:
console.log(navigator.userAgent);
Or by screen size:
console.log(screen.height);
console.log(screen.width);

- 506
- 9
- 22
-
-
6@James111 If I were your employer relying on you to write precise code I'd be worried about your definition of the word "exactly" – Dexygen Mar 03 '16 at 01:18
-
-
@James111 Just because I was yet writing my answer while you sent yours, and i didnt see it until now you commented mine – Fabius Mar 03 '16 at 01:27
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.
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
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

- 433
- 2
- 8