0

So I need to include javascript and jquery in my html page that will check whether visitors are using mobile browsers, and display a video at different sizes depending accordingly.

I've tried several ways of doing this, but have yet to find something that actually works.

What I need is something like:

if (isMobile()) {
   //display larger
else {
   //display smaller
}

Can anyone help?

Mosh Feu
  • 24,625
  • 12
  • 74
  • 111
Sharendale
  • 31
  • 4
  • 1
    Possible duplicate of [What is the best way to detect a mobile device in jQuery?](http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery) – Andrew Li Jun 01 '16 at 06:41

2 Answers2

1
if (!('ontouchstart' in window)) {
  // is desktop
  elVideo.src= 'desktop.mp4';
} else {
  // is mobile
  elVideo.src= 'mobile.mp4';
}
poashoas
  • 1,453
  • 2
  • 17
  • 34
  • Thank you for your response. However, I don't actually have 2 different sizes for the video. is there anyone to do by resizing? – Sharendale Jun 01 '16 at 15:39
0

You can detect like this


    if(jQuery.browser.mobile)
    {
       //code to be executed when device is mobile
    }
    else
    {
       //code to be executed when device is not mobile
    }

  • 2
    Just a heads up, the jQuery.browser method was deprecated and removed in jQuery 1.9. View the [docs](http://api.jquery.com/jquery.browser/) – jhaskell Jun 09 '16 at 20:47