Mobile detection for specific parts of websites

和自甴很熟 提交于 2019-12-02 17:06:56

问题


I am beginner in web development and I'm having trouble wrapping my head around this problem.

I have taken a video and encoded it into an mp4 file and an ism file. I have two different video tags- one that will play each file. For the website I'm working on I would like it to use one of the video tags if the website is being viewed on a mobile device, and the other if it is not. Right now the website is in HTML5. Thank you for any help you can give!


回答1:


The video tag already supports alternate sources. The article here describes how to include multiple sources for a video (because some browsers don't work with certain codecs). Like so:

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

For mobile checks you can use JavaScript CSS media queries:

function isMobile() {
    return window.matchMedia( "(max-width: 320px)" );
}

See this article




回答2:


you could either use UserAgent based detection to decide what to show (not recommended as you have to maintain it) or canPlayType() with the codec you are using to see if the browser supports it (better option)



来源:https://stackoverflow.com/questions/15097554/mobile-detection-for-specific-parts-of-websites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!