'对象预期'来自IE8使用YouTube API的错误

时间:2011-05-30 13:26:49

标签: javascript internet-explorer-8 youtube-api

使用一些用于使用Data API显示YouTube视频的JavaScript,在IE8中遇到问题。

我得到的错误是'对象预期',源于第二个代码行。

// <![CDATA[
var baseUrl = 'http://www.youtube.com/';
var swfUrl = constructUrl(baseUrl);

// allowScriptAccess must be set to allow the Javascript from one
// domain to access the swf on the youtube domain
var params = { allowScriptAccess: "always", bgcolor: "#cccccc" };

// This sets the ID of the DOM object or embed tag to 'myytplayer'.
// You can use this ID to access the swf and call the player's API
var atts = { id: "myytplayer" };
var flashvars = {};
swfobject.embedSWF(swfUrl, "ytapiplayer", "220", "125", "9", null,
  flashvars, params, atts);
//]]>

是否有人遇到此错误,您是否有任何经过测试的解决方案?

1 个答案:

答案 0 :(得分:1)

IE会在很多事情上吐出“预期的对象”错误,包括未定义的函数。最有可能在此函数的上下文中,您没有包含定义constructURL()的库。