Only R
Only R

Reputation: 55

__flash__removeCallback is undefined errors in IE9 while removing the dom element

probably the duplicate of '__flash__removeCallback' is undefined when deleting DOM element with Youtube iframe

I went through some sites but could not found the exact solution of why youtube throws this exception while removing the dom element with youtube iframe and what will be the solution??

Some solution that i have got are :

  1. ytplayer.getIframe().src=''; -> I dont know how this could solve my problem?

2.$('#youtube iframe').attr('src', ''); $('#youtube').remove() -> I have tried this but won't worked.

3.hide iframe before remove the parent element -> won't worked.

Please help me to resolve this issue.

Upvotes: 4

Views: 3284

Answers (4)

Juan
Juan

Reputation: 441

You can also fix Flash's callback removal function by overwriting it with your own. This issue is not particularly connected to video apps only. In the example below I overwrite it right before the page gets unloaded, but it can happen anytime after the swf loads.

window.onbeforeunload = function () { this.__flash__removeCallback = function (instance, name) { if (instance == null) return; // <-- this line prevents the error instance[name] = null; } }

Upvotes: 0

FoxShrill
FoxShrill

Reputation: 91

This worked for me in IE9.

 $(window).unload(function() {
        jwplayer('video1').stop();
        jwplayer('video1').remove();
        $(window).remove();
    });

Upvotes: 0

JasonH
JasonH

Reputation: 1241

The below code should work across all browsers (and not produce the IE9/IE10 error you describe above).

function playVideo() {
    $('#video iframe').attr('src', 'http://www.youtube.com/embed/VIDEO_ID_HERE');
    $('#video iframe').fadeIn();
}

function stopVideo() {
    $('#video iframe').attr('src', '');
    $('#video').fadeOut();
}

The end result is a video that will load when button is clicked, and will safely remove the video without causing memory leaks in IE9/IE10.

Upvotes: 1

igorski
igorski

Reputation: 954

This appears to be an IE9-only bug.

It occurs when a Flash object interacts with a HTML document using JavaScript (ExternalInterface on the Flash/ActionScript-side) and rears it's ugly head when an IFRAME containing the HTML document w/ the Flash Object comes into play.

Seeing how you specify you're using the YouTube API, there is sadly nothing you can do to make sure the Flash unregisters itself and won't call JavaScript functions (or vice versa) when it's time to remove it as you rely on third party software running outside your applications domain.

If you don't NEED the YouTube API, but merely a quick way to get a video within your application, the safest bet is to use an old style object embed for IE9 and the API / IFRAME embedding for the rest of the sane world.

<object width="{WIDTH}" height="{HEIGHT}">
  <embed src="https://www.youtube.com/v/{VIDEO_ID}?version=3&autoplay=1"
         type="application/x-shockwave-flash"
         allowscriptaccess="always"
         width="{WIDTH}" height="{HEIGHT}"></embed>
</object>

Removing above object (you can use SWFObject's "embedSWF" and "removeSWF" just fine for this btw) will get the video player off your page, without throwing any _flash_remove.. warnings.

If you NEED the YouTube API / control over the video player state:

Have you tried invoking the "destroy"-method on the ytplayer ? Unvoke the destroy and while I'm reluctant to posting "answers" using timeouts, give the Flash object some time to unregister BEFORE your set the source of the iframe to an empty string (so the document unloads), then clear the iframe or it's parent container.

Though I remember from a previous project this drove us mad (the context being a single-page interface where videos were dynamically added and removed) and we resorted to writing our own Flash player fallback using the AS3 YT code. That's how annoying it got.

Upvotes: 3

Related Questions