How to prevent autoplay on mobile

Look at framer.com on desktop: the promo video autoplays. Look at it on mobile: it embeds as an ordinary YouTube video, with a manual play button. The behavior is different because video autoplay on mobile is much more annoying: video takes a big bite into your mobile data usage.

How does framer.com achieve this? By switching on whether the user-agent suggests that the device is a mobile. Here’s some equivalent code:

function isMobile() {
    return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
Tagged .

Similar posts

More by Jim

Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!

This page copyright James Fisher 2017. Content is not associated with my employer. Found an error? Edit this page.