Issue: Can't stop iframe from loading (JS)

Hello everyone, I am glad for joining sitepoint.
So, I am patching a really crowded web radio player and sadly everything has to be patched in production mode.

<div class="hidden_element" id="hideflash">
    <iframe frameBorder="0" width="315" height="45" id="flash" scrolling="no" src="THESOURCE"></iframe>
</div>
<script type="text/javascript">
    var firefox = /Firefox/i.test(navigator.userAgent);
    if (Modernizr.flash && !firefox) {
        // Supports Flash and is not Firefox
        $("#html5").addClass("is-splash");
        $("#html5").addClass("is-paused");
        $('video').removeAttr("autoplay");
        $("#seekbar").hide();
        $("#html5").hide();
    } 
    if (firefox) {
        // Firefox Detected- Normal HTML5 Initiation
        document.getElementById("flash").contentDocument.close();
        window.frames[0].stop();
        window.frames[0].document.execCommand('Stop');
        $("#hideflash").hide();
    }
    if (!Modernizr.flash) {
        // Flash is not supported
        document.getElementById("flash").contentDocument.close();
        window.frames[0].stop();
        window.frames[0].document.execCommand('Stop');
        $("#hideflash").hide();
    }
</script>

I use a Modernizr custom script to determine wether the browser is Firefox or Supports Flash. If none of this is true I unload the HTML5 Player and the flash iframe comes up as planned. If however Firefox or lack of Flash support is detected I hide the iframe and initiate the HTML5 Player.

This is a pretty problematic setup but this is the only way to meet my company’s demands. The main issue is that the code for stopping the iframe from loading sometimes works and sometimes it doesn’t.

Any suggestions on this tricky one ?

Thank you in advance.

Hi @KonstantinosKoletsas! Well what do you mean by this? How can you reproduce the problem?

Anyway, maybe you could simply remove that iframe from the DOM altogether as a workaround… like

var iframe = document.querySelector('iframe');
iframe.parentNode.removeChild(iframe);

Why don’t you do that the HTML way by simply wrapping the flash version inside the HTML5 player code so that it will be tried when the HTML5 code doesn’t work and ignored if it does work.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.