I am fairly new with programming with Javascript. I'm working on a website that I need to know if access to my website is from a mobile or not. So, my question is how do I code it to find out it the website visitor is using a mobile device or not? Reason is I will be playing live streaming video and will need to size the video based on whether a mobile or not. Appreciate the responses. Ray
Hi Your browser will have a thing called "Development Tools". The easiest way to find it is to do a right mouse click over your page and select "inspect" from the menu options. Once in there you'll find a lot of information that will probably be a bit overwhelming. What you're looking for is up in the top left-hand corner (typically, may vary a bit between browsers). Find the symbol I've circled and your page will shrink to a default phone size. The menu at the top will let you pick different phone and tablet options. FWIW this is a straight HTML question and nothing to do with javascript.
Maybe you misunderstand. I need a Javascript solution to determine what kind of device is accessing my site. I need my server to determine if access to my website is from a mobile or not and then adjust the video size.
Just look at the user_agent https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
Why would you want to do this using javascript? Just make your site responsive / fluid and the video will adjust its size to whatever screen automatically.
as @qwikad.com said, NOT JavaScript's job. That's layout. That's CSS' job. At MOST you would/should have an extra DIV to use the padding trick to force the aspect ratio to stay correct if the video is in a non-scaling container. (like the iframe youtube favors). Don't just dive for JavaScript as the answer to all your problems, generally that just shows you don't know enough HTML or CSS to be using JS in the first place.