Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript playing music on a site Re: playing music on a site

#124247
tomrogers123
Member

Playing around, this JS seems to work:

var selection = window.confirm(‘This page has sound on it. Confirm to play’),
testTrack = document.getElementById(‘audio’);

if(selection == true) {
testTrack.load();
testTrack.play()
}

That doesn’t sort out your pause link quite yet (can add if needed), but it does make it so it will only start playing if they click OK at the confirmation. If you need anymore help let me know. Interestingly also, I couldn’t just update the codepen because confirm doesn’t seem to run.

I do kinda agree with @chrisburton too though in that having a big popup when the page loads is obtrusive and may hinder good UX. But hey, if that’s what you need that’s fine I guess :)