Forum Moderators: open

Message Too Old, No Replies

JS to force auto-playing in modern browsers

         

abrodski

8:29 pm on Jul 22, 2019 (gmt 0)

10+ Year Member



Hello!
Is there a way to use JS to bypass a recent limitation in modern browsers to autoplay music?
I activated an autoplay in a Joomla music player plugin and I also used JS code via Custom HTML module
<script type="text/javascript">
var source = 'https://example.ru/1.mp3';
var audio = new Audio();
audio.addEventListener('load', function() {
audio.play();
}, true);
audio.src = source;
audio.autoplay = true;
</script>




[edited by: not2easy at 9:55 pm (utc) on Jul 22, 2019]
[edit reason] exemplified (ToS/Charter) [/edit]

Dimitri

9:00 pm on Jul 22, 2019 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



I know I'll be off -topic, but, no matter if your motivation is legitimate, I would suggest NOT to attempt to bypass the auto-play blocker of browsers. First of all, this is certainly not possible, and secondly playing a sound automatically to all visitors is, in my opinion, an extremely bad idea. There is a reason this feature was developed...

lucy24

10:15 pm on Jul 22, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there a way to use JS to bypass a recent limitation in modern browsers to autoplay music?
Probably, but why on earth would you want to do something that will simply cause human users to leave your site instantly? Are you trying to sabotage a competitor’s site?

tangor

6:17 am on Jul 23, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can't post your website per TOS at WW ... but I'll never see it even by accident, and the majority of JS off, Script killer, and ad blocker users growing by leaps and bounds (not to mention mainstream browsers actively killing video/audio autorun) will not make your day ... or let your js script work in the first place.

There's a reason why tech and users---the web in general---are heading in this direction. AUTOPLAY is obnoxious!

Dimitri

10:56 am on Jul 23, 2019 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



In all events, when you use in the same sentence "to force" and "bypass"... :)