yossi
yossi

Reputation: 296

How to stop the audio playing when I navigate to another page in the same file?

I have a file with a story Demo story. When I move to the next page, I am using the right arrow key. The old page continues playing while I am in the new page and I need to hear the new record.

  1. How can I create an event or make another solution when I go to the next page to stop the old playing?

I am still in the same file when I go to the next page.

<footer>
    <div style="position:relative;width:100%;margin-top:0px;margin-bottom:0px;">
    <div style="width:960px;height:94px;position:relative;margin:0px;margin-left:auto;margin-right:auto;margin-top:5px;margin-bottom:5px;padding:0px;overflow:hidden">
        <audio controls="controls">
          <source src="CarlyAndHerLemons1.ogg" type="audio/ogg" />
          <source src="CarlyAndHerLemons1.mp3" type="audio/mpeg" />
        </audio>
</footer>

I think I should use by code similar to document.getElementById('demo').pause()

Many thanks.

Upvotes: 0

Views: 1220

Answers (1)

fardjad
fardjad

Reputation: 20424

Give your audio tag an ID and then use:

document.getElementById('yourAudioTagID').pause();

Also this page might be useful.


Edit:

Here is a JSFiddle Demo.

Upvotes: 1

Related Questions