6

How to check Mobile/Web in HTML Meteor for loading UI? .

if mobile //here how to check if it is mobile or web
{
   {{>template}}// mobile body
}
else
{
  {{>template}}//web body
}

I am new to Meteor. So please suggest me what to do?

meager
  • 209,754
  • 38
  • 307
  • 315
Venkat
  • 821
  • 13
  • 31
  • 1
    Related: http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-handheld-device-in-jquery – nathan-m Feb 13 '14 at 04:55
  • 1
    if you want to do this on the client then there is nothing special about meteor here. Please just look for answers for html/javascript. You could also just use one of many responsive design frameworks (e.g., bootstrap, or foundation). On the server this would be a lot harder. – Christian Fritz Feb 13 '14 at 04:56
  • 1
    Actually, while you can do this in typical JS / JQuery way, Meteor makes it easier. The question is legit. – Hubert OG Feb 13 '14 at 06:07
  • 1
    There is a [good discussion](https://groups.google.com/forum/#!topic/meteor-talk/ku7kvNJp8ek) over at the meteor-talk google group regarding this very subject. – Serkan Durusoy Feb 13 '14 at 08:23

3 Answers3

8

You can do that easily with device-detection package.

First, install it via:

meteor add mystor:device-detection

Then you can use the provided helper methods like Meteor.Device.isPhone(), or directly from Spacebars: {{#if isPhone}}Phone{{/if}}. See the readme on Github for details.

Richard de Wit
  • 5,772
  • 7
  • 42
  • 50
Hubert OG
  • 18,454
  • 6
  • 40
  • 70
5

If you simply want to check whether the app is running on a mobile environment you can use:

if(Meteor.isCordova)

Check out the other functions as well

mhsallam
  • 159
  • 2
  • 4
1

If someone is still looking for this, he can try this JS test:

if (/Mobi/.test(navigator.userAgent)) {
    //on Mobile
}else{
    //not on mobile
}
gyre
  • 14,437
  • 1
  • 32
  • 46