Skip to content

Instantly share code, notes, and snippets.

@giiska
Created October 21, 2014 08:54
Show Gist options
  • Save giiska/42dcbe2443c9d356e936 to your computer and use it in GitHub Desktop.
Save giiska/42dcbe2443c9d356e936 to your computer and use it in GitHub Desktop.
How can I autoplay media in iOS >= 4.2.1 Mobile Safari?
There is one way to play the video/audio file automatically on 4.2.1. Create an iframe and set its source to the media file's URL and append the iframe to the body. It'll be autoplay.
var ifr=document.createElement("iframe");
ifr.setAttribute('src', "http://mysite.com/myvideo.mp4");
ifr.setAttribute('width', '1px');
ifr.setAttribute('height', '1px');
ifr.setAttribute('scrolling', 'no');
ifr.style.border="0px";
document.body.appendChild(ifr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment