Display notification div with JAVASCRIPT audio

0

So, I made a code with jquery that after 8 seconds of open index page displays a message div with audio.

$(document).ready(function () {
    // Mostra a div após 8 segundos
    setTimeout(function() {
        $('.informativo').show().append('<embed src="<?php echo $address ?>sound.mp3" autostart="true" hidden="true" loop="false">');
        // Esconde a div após 8 segundos
        setInterval(function () {
                $('.informativo').fadeOut();
        }, 8000);
    }, 4000);        
});    

<div class="informativo">
    <p>Mensagem de alerta com audio</p>
</div>

But I'm having a problem that if I open this index page and mute the tab, the div appears in the normal index tab, but the audio only runs when I go back to the index!

I wanted the audio in the embed to roll even though I was on another flap!

    
asked by anonymous 19.06.2017 / 22:51

1 answer

0

The code is being used in PHP, it would be the index.php, configure a file in JS that has PHP and calls it in the header of the index;

 <embed src="<?php echo $address ?>sound.mp3" autostart="true" hidden="true" loop="false">

When you exit from index.php the other page can not find the music directory because you might have to place the code only on one page.

    
24.06.2017 / 00:14