This is an issue which has taken me several days to fix, but this has been my first time working with js/jQuery.
The issue is detailed here: MSDN
In summary IE9 doesn't allow an iframe to be removed from the DOM if it will have javascript executed. This is to address a memory leak issue. IE9 will throw undefined property errors.
This affects multiple modal plugins out there and would probably be more effectively addressed in the colorbox library but that's a little beyond my skill level.
The two ways of fixing this issue are either to append the iframe to an element in the DOM, load the content and then remove it from the DOM again, or change when the src is loaded which is what I've done. To keep IE9 happy you have to also unload the src (or append to the DOM) before the modal is closed otherwise an endless number of errors.
Thankfully Colorbox has hooks for each of the key points in the open/close process to bind to. Below are the additions made to colorbox.js (sites/all/modules/colorbox/js/colorbox.js):
$(document).bind('cbox_open', function(){
uhref = $("#IframeID").attr('src');
$("#IframeID").attr('src', "about:blank");
//
$(document).bind('cbox_complete', function(){
$("#IframeID").attr('src', uhref);
//
$(document).bind('cbox_cleanup', function(){
$("#IframeID").attr('src', "about:blank");
//
$(document).bind('cbox_closed', function(){
$("#IframeID").attr('src', "about:blank");
Full code looks like this with additions to prevent the parent window from scrolling. This was altered for youtube videos inside a colorbox:
(function ($) {
uhref = "" //define global var
Drupal.behaviors.initColorbox = {
attach: function (context, settings) {
if (!$.isFunction($.colorbox)) {
return;
}
$('a, area, input', context)
.filter('.colorbox')
.once('init-colorbox-processed')
.colorbox(settings.colorbox);
}
};
{
$(document).bind('cbox_open', function(){
$('body').css({overflow:'hidden'}); //prevent background scrolling
uhref = $(".youtube-player").attr('src'); //get src before it's loaded/changed
$(".youtube-player").attr('src', "about:blank"); //change src before IE9 chokes on it
$('#slideshow-div').rsfSlideshow('toggleShow'); //stop slideshow - performance issues on older machines
});
}
{
$(document).bind('cbox_complete', function () {
Drupal.attachBehaviors('#cboxLoadedContent');
$(".youtube-player").attr('src', uhref); //reload the correct src now that cbox has finished loading
});
}
{
$(document).bind('cbox_cleanup', function(){
$(".youtube-player").attr('src', "about:blank"); //remove src again so IE9 doesn't present endless '__flash__' js errors
});
}
{
$(document).bind('cbox_closed', function(){
$('body').css({overflow:'auto'}); //allow scrolling again on parent window
$('#slideshow-div').rsfSlideshow('toggleShow'); //restart slideshow - performance issues on older machines
});
}
})(jQuery);
This would need a dynamic way of looking for iframe content and finding the iframe class or id to be applied to this module.
Hope this is helpful to someone.
Comments
Comment #1
frjo commentedComment #2
barakman commentedI've encountered the same problem yesterday (11/09/2012).
First of all, this is a disgrace that MS releases a browser with such defects (memory leaks in the Javascript interpreter).
One way to solve this problem is by deleting all browser history. Obviously, you wouldn't expect the user on the other side to do it every time they use IE9 to connect to your website.
Another option is as follows:
I've encountered the problem when trying to embed YouTube videos into my website.
Initially I was using Goggle's swfobject.js.
This worked good on all three browsers (Chrom, Firefox and IE). However, since it relied on Flash to play the videos, it did not work on iPhone (Safari), which does not support Flash.
So I moved to Youtube's iframe_api, which does not rely on Flash. Now it works on iPhone but not in IE!
The main difference between the two, with regards to this problem, is that swfobject adds an OBJECT element into the HTML, while iframe_api adds an IFRAME element into the HTML.
The IFRAME element, which contains a YT player, is not de-allocated when the window is closed, causing memory-leaks in the IE.
If you're problem is due to using iframe_api, and you don't mind using swfobject instead, then you can choose that as a solution.
Comment #3
frjo commentedThis seems not to be a common problem and I assume it's fixed in IE 10.
Comment #3.0
frjo commentedRefined the code so it worked -original posted replacement for colorbox.js failed without "youtube-player" present. Comments added to custom lines.