0
So, I made a code with jquery that after 8 seconds of open index page displays an audio message div.
$(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 change tab, the div appears in the normal index tab, but the audio only runs when I go back to index!
I wanted the audio in the embed to actually run, me being in another tab!
You can post the complete code with the relative HTML so we can test?
– user60252
In fact if the audio is already running and change tab it will continue running.
– user60252
I posted the necessary HTML
– Jaider Master Info
@Leocaracciolo so the sound is really fast! after 8 seconds it appears with the div and if I open the page and change tab before 8 seconds, it does not play! It only rings when I return to the system tab
– Jaider Master Info
This, but if it is already running, it will continue running regardless of which page you are browsing since q vc does not close the audio tab
– user60252
Guy really your code there is no mistake! Here mine does not work the way
– Jaider Master Info
Take the source code of the page
– user60252
I just put the audio URL in your code
– user60252
Strange too dude, I’ll try to clear my cache! To see if it helps anything!
– Jaider Master Info
which browser?
– user60252
Chrome and updated!
– Jaider Master Info
Instead of using
setTimeout()
, Try replacing delay with delay:$('.informativo').show().apped('...').delay(8000);
, this way you will shoot the waiting for the event right at the beginning, thissetInterval()
will be repeating itself eternally while the tab is open every 8 seconds, was that right? The audio will only stop if you close the tab.– Ivan Ferrer