How to enable autoplay on modern browsers


Problem

On modern browsers, using autoplay is hard. This is usually a good thing, but can be cumbersome in some scenarions, for example on slideshow-type sites like, as a well-known example, fauux

.

Solution

Consider weather using autoplay by default makes sense, or if it should rather be opt-in. If you think blasting the user without warning makes sinse, use my horribly janky JavaScript :3

To do this, either download the autoplay_enable.js, upload it to your own site and use that (better approach)
or include this code snippit that loads it from my site in the <head> (important) of your page(lazy):

<script src="https://h3.neocities.org/autoplay_enable.js"></script>

It automatically seeks ot any <audio> tag with the autoplay attribute set, so you will not have to change anything. Just use the autoplay attribute as normal. It will not interfere with other JS that pauses/plays audio tags.

How this works

Audio on modern browsers will not be allowed to play, unless its activated by a user interaction like clicking, tapping, keyboard, etc.
The scripts triggers on all of those events and triggers the autoplaying ONCE. This is to not interfere with other JS.
I commented the script a bit so that you can understand it better.


Simplified version

hosma has made a simpler, smaller, more optimized version of the autoplay enabler.

You can visit their website here: hosma.neocities.org