[英]click() in javascript doesn't work but in console it works fine
我想在我的网站上播放来自soundcloud的音乐,但不能在Chrome中自动播放。 因此,为解决此问题,我决定在页面加载时自动单击“播放和暂停”按钮。 但我现在有一个新问题,而click()无法正常工作:(
这是代码:
setTimeout(function() { console.log("a"); document.getElementById("play").click(); }, 1000);
<section id="audioW"> <a href="#" id="play" onload="autoclick('#play')"><img src="https://saeedrezvanian.com/wp-content/themes/saeedrezvanian/img/play.svg" alt="control" id="control"></a> <a href="https://soundcloud.com/barfakmusic" target="_blank" id="audio">Barfak</a> </section>
“ a”出现在控制台中,但播放按钮从未单击
我希望有人可以帮助我
反驳性的问题:如果只需要HTMLElement.click()
他们为什么会在autoplay
属性和HTMLMediaElement.play()
方法上设置此限制?
您需要一个USER-手势 。
对于看起来像错字的点击问题: onload
=> onclick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.