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);
也許可以 祝你好運。