Why does YouTube's JavaScript API cause errors when unloading in IE8?
At this point I'm stumped. The below embed code causes "Object Required" errors every time I refresh the page in Internet Explorer 8 (probably other versions of IE as well but I don't have them readily available for testing).
It works just fine in other browsers.
The oh so simple code:
<object width='425' height='344'>
<embed src='http://www.youtube.com/v/3kU1x9StavM?enablejsapi=1' type='application/开发者_如何学Pythonx-shockwave-flash' width='425' height='344' allowscriptaccess='always' allowfullscreen='true'></embed>
</object>
It errors even when that is literally the only content on the page.
Does anyone have any ideas? I don't have the option of using swfobject because I'm going to be rewriting embed tags to enable jsapi (I'm writing an interactive transcript plugin that needs to essentially load itself and require no extra action on the part of the publisher to use).
Embedding with SWFObject is definitely a right way to do it. We have encountered exactly the same problem in IE6+ and it went away once swf object was used to embed the video.
There is a problem with the js api on IE... others have talked about it here http://support.soundcloud.com/soundcloud/topics/sets_breaking_in_ie8 If you remove the jsapi parameter or set the value of allowscriptaccess to sameDomain or never the errors disappear but you can't use the API anymore :(
Unfortunately I was never able to get to the bottom of this. Which is frustrating.
Ultimately IE has some issues with binding events to flash objects when the object is created out of order.
I ended up just using swfobject.js after all. They work some magic somewhere that I couldn't reproduce.
This is occurring because of javascript calls on page unload to an object that no longer exists (the video embed). The code below removes the embed before the page unloads, hence no more errors in IE8:
Event.observe(window, 'beforeunload', function(){
var player = $("video-embed-element");
player.remove();
}, false);
I'd also highly recommend surrounding the code with an IF statement that checks to make sure the browser is IE8, as described here
精彩评论