jQuery OEmbed插件 - 错误:对象不支持此属性或方法
-
06-07-2019 - |
题
我目前正在使用以下jQuery插件:jQuery OEmbed。此插件适用于FF,Chrome和Safari。但是,我在IE7中遇到了问题。我已经将我的代码剥离到非常简单,但仍然无法弄清楚会导致以下错误的原因:
Error: Object doesn't support this property or method.
错误所指的行是:
$("#container").oembed("http://www.youtube.com/watch?v=nue4pvzuyOo");
这是我的HTML(再次,非常基本):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery-oembed explicit insert example</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="oe.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$("#container").oembed("http://www.youtube.com/watch?v=nue4pvzuyOo");
});
</script>
<div id="container"></div>
</body>
</html>
该插件的javascript可以在这里找到。
有趣的是,这个错误不会发生在IE8中 - 只有IE7。
关于可能导致此错误的任何想法?
解决方案
JSLint 报告,除了其他问题之外,您链接到的插件代码在对象文字中还有一个额外的逗号。纠正这个似乎在IE7中修复它。
修复:
// Plugin defaults
$.fn.oembed.defaults = {
maxWidth: null,
maxHeight: null,
embedMethod: "replace", // "auto", "append", "fill"
};
更改为:
// Plugin defaults
$.fn.oembed.defaults = {
maxWidth: null,
maxHeight: null,
embedMethod: "replace" // "auto", "append", "fill"
};
请注意&quot; replace&quot;
。
工作演示: http://jsbin.com/oxitu
不隶属于 StackOverflow