Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
Is there any working way to autoplay audio on all major browsers using Javascript?

I have set up some HTML & Javascript that can control the playing of an audio track on a webpage, I really like simplicity of JavaScript with play/stop function but I can't make it play automatically. Here's my javascript code:

$('body');
var audio = document.getElementById("audio-player");
audio.volume = 0.2;

if ($(window).length) {
  $('.bg-player').css({
    'visibility': 'visible'
  });
  
  $('body').addClass("audio-on");
  
  if ($('body').hasClass('audio-on')) {
    $('body').removeClass('audio-off');
  }
  
  $(".bg-player").on('click', function() {
    $('body').toggleClass("audio-on audio-off");
    
    if ($('body').hasClass('audio-off')) {
      audio.pause();
    }
    
    if ($('body').hasClass('audio-on')) {
      audio.play();
    }
  });
}

I tried to add the autoplay property but no success:

audio.autoplay = true;

I would like know if there is a way for play the file on the page load.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's a browser security feature to not autoplay an audio unless there is some user interaction.

https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#new-behaviors

Autoplay with sound is allowed if:

User has interacted with the domain (click, tap, etc.). On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound. The user has added the site to their home screen on mobile or installed the PWA on desktop.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda