'__flash__removeCallback' is undefined when deleting DOM element with Youtube iframe

家住魔仙堡 提交于 2019-12-04 20:40:05

问题


I have a div with a Youtube video embedded via iframe.

<div id="container">
    <div id="video">
        <iframe width="480" height="360" src="http://www.youtube.com/embed/LiyQ8bvLzIE" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

I change the content of #container with an ajax call

$.get(url, function(data) {
    ('#container').html(data);
}

Now I get the following error in IE9: "SCRIPT5009: '_flash_removeCallback' is undefined".

I tried removing, deleting,... the video and/or iframe before the ajax call but that doesn't work:

<script>
    $('#video').html('')
</script>

<script>
    $('#video').empty()
</script>

<script>
    $('#video').remove()
</script>

<script>
    $('#video iframe').attr('src', '')
    $('#video').empty()
</script>

<script>
    $('#video').hide()
    $('#video iframe').attr('src', '')
    $('#video').empty()
</script>

...

But now I'm out of idea's...


回答1:


Finally I got the solution.

I don't know which server side language you are using, I'm using PHP. Anyway find if the browser is IE9 then use object tag.

if (preg_match('/MSIE 9.0/', $_SERVER['HTTP_USER_AGENT'])) { /*for IE 9.0 generate with objace tag*/ ?>
     <object type="application/x-shockwave-flash" data="VIDEO_URL">
      <param name="movie" value="VIDEO_URL" />
      </object>
 <?php } else { /*rest of all browsers,in iframe*/ ?>
      <iframe src="VIDEO_URL"></iframe>
 <?php } ?>

In short use object tag for IE9 and iframe for rest.




回答2:


I got the solution.

ytplayer.getIframe().src='';



回答3:


If you still want to continue using the iframe code, you can remove the iframe src by calling removeAttr (instead of trying to set it to blank).

$('#video iframe').removeAttr('src')



回答4:


I was receiving the same error and came to my own solution. I felt that using the old "object" solution for IE9/IE10 was not a true solution because you should never have to code specifically for one browser.

The difference in my situation, I simply needed a video to pop-up, and then stop playing and disappear when close button was clicked.

Using your provided code...

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();
}


来源:https://stackoverflow.com/questions/11543888/flash-removecallback-is-undefined-when-deleting-dom-element-with-youtube-if

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!