Search code examples
javascriptiframeinternet-explorer-8internet-explorer-7

IFrame causing back button issues


I am currently having an issue with IE8/7 (I do not have a choice, I have to add support for these before anyone moans) where IFrames with youtube videos are causing an issue with adding extra URLs into the history so when hitting back I am having to do it 2-3 times before actually getting to go back, my current solution seems to work in newer browsers but not the two I am having an issue with, current solution is:

<script type="text/javascript">
$(document).ready(function () {
    $("iframe").each(function () {
        var ifr_source = $(this).attr('src');
        if (ifr_source.indexOf("youtube") != -1) {
            var parent = $(this).parent();
            var ifr = $(this).detach();
            var wmode = "wmode=transparent";
            if (ifr_source.indexOf('?') != -1) {
                var getQString = ifr_source.split('?');
                var oldString = getQString[1];
                var newString = getQString[0];
                $(this).attr('src', newString + '?' + wmode + '&' + oldString);
            }
            else $(this).attr('src', ifr_source + '?' + wmode);
            ifr.appendTo($(parent));
        }
    });
});


Solution

  • just answering my own question here...

    Simply adding this into the mix

                    var frame.src = 'javascript:parent.getFrameHTML()'
    

    Has resolved the issue!