@Jasper_Holton's profile photo

A Handy Audio Fix For Iframes Using jQuery This is how I play pause audio in the document with iframes loaded in so audio doesn't play more than once in the document. This fix changes the site to fix double audio playing in multiple iframes. This code is included in each iframe and in the main document.

$(function() {
    $("audio").on("play", function() { // When each audio is played in main document
        $("audio", window.parent.document).not(this).each(function(index, audio) { // Get each audio that isn't this one
            audio.pause(); // Pause it
        playing = this; // Save the audio that's playing
        $("iframe", window.parent.document).each(function(index, iframe) { // Get all iframes in parent document
            $(iframe).contents().find("audio").not(playing).each(function(index, audio) { // Filter audios that shoudln't be playing (not the one we clicked)
                audio.pause(); // Pause the audio
This simple code pauses the audio elements on my site as a new one is played. It can be used to prevent duplicate audios from playing, and it runs on all audios and iframes so it can be used in any document. It should be integrated in the parent document and each iframe of the scrolling page.

@Jasper_Holton, likes this,

Pinterest logo
Tumblr logo VK logo

https://uglek.com/post/424/ -

© Uglek, 2022

Terms of Use and Privacy Policy