您的位置:首页 - 教程 - HTML5 - 正文
audio标签的autoplay属性在移动端下,无效
audio标签的autoplay属性在移动端下,无效
HTML5新标签audio,在移动端(测试ios系统)下,页面初次加载,音乐无法自动播放(尽管设置了autoplay=“autoplay”),在PC端能正常播放;


Starting from iOS 4.2.x, the download of media will not be started if there isn’t a user-input event, like touchstart.
但是你可以曲线救国,比如:
Create an iframe and set its source to the media file's URL and append the iframe to the body.
var ifr=document.createElement("iframe");
ifr.setAttribute('src', "http://cms.hovertree.com/hovertreesound/hovertreesnow.mp3");
ifr.setAttribute('width', '1px');
ifr.setAttribute('height', '1px');
ifr.setAttribute('scrolling', 'no');
ifr.style.border="0px";
document.body.appendChild(ifr);
也许可以 祝你好运。

评论: