IE 抛出“未指定错误”重新加载嵌入了 swfobject 的页面时
我有一个简单的页面,上面嵌入了 swfobject。
看起来 IE 对嵌入对象的“过滤器”属性有问题。
我的测试页面如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<script type="text/javascript" src="../scripts/swfobject.js"></script>
<script type="text/javascript" src="../scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var url = "";
$(function()
{
var flashvars = {};
var parameters = {};
var attributes = {};
flashvars["data-file"] = url;
parameters.wmode = "transparent";
swfobject.embedSWF("test.swf", "graph1", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, parameters, attributes);
});
</script>
<style type="text/css">
#graph1
{
margin:30px;
height: 400px;
width: 600px;
}
</style>
</head>
<body>
<div id="graph1"></div>
</body>
</html>
注意: test.swf
文件是来自 下载页面。
现在,当我重新加载页面时,它会在 IE 上抛出“未指定错误”,但不会在 Firefox 上抛出“未指定错误”,其中过滤器属性设置为“未定义”。
似乎导致错误的代码位于 swfobject.js v2.2(第 494-504 行)中:
/*! SWFObject v2.2 <http://code.google.com/p/swfobject/>
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
function removeObjectInIE(id) {
var obj = getElementById(id);
if (obj) {
for (var i in obj) {
if (typeof obj[i] == "function") {
obj[i] = null; // when (i == 'filters') we get the error
}
}
obj.parentNode.removeChild(obj);
}
}
有谁知道为什么会发生这种情况?
I have a simple page with an swfobject embedded on it.
Looks like IE has problems with the 'filters' property on the embedded object.
My test page looks like that:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<script type="text/javascript" src="../scripts/swfobject.js"></script>
<script type="text/javascript" src="../scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var url = "";
$(function()
{
var flashvars = {};
var parameters = {};
var attributes = {};
flashvars["data-file"] = url;
parameters.wmode = "transparent";
swfobject.embedSWF("test.swf", "graph1", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, parameters, attributes);
});
</script>
<style type="text/css">
#graph1
{
margin:30px;
height: 400px;
width: 600px;
}
</style>
</head>
<body>
<div id="graph1"></div>
</body>
</html>
note: the test.swf
file is the one swfobject package from the download page.
now when i reload the page, it throws an 'Unspecified error' on IE, but not on firefox in which the filters property is set to undefined
.
the code that seems to cause the error is in swfobject.js v2.2 (lines 494-504):
/*! SWFObject v2.2 <http://code.google.com/p/swfobject/>
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
function removeObjectInIE(id) {
var obj = getElementById(id);
if (obj) {
for (var i in obj) {
if (typeof obj[i] == "function") {
obj[i] = null; // when (i == 'filters') we get the error
}
}
obj.parentNode.removeChild(obj);
}
}
Does anyone have any idea why this might be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两件事立即引起了我的注意:
第一:
您将匿名函数(包含 SWFObject 代码)包装在 jQuery 'dollar' 声明中。 jQuery Dollar 函数“接受包含 CSS 选择器的字符串,然后使用该字符串来匹配一组元素”。
您的函数不会返回任何内容,因此当 jQuery 尝试使用 null 引用作为 CSS 选择器时,它将导致 JavaScript 错误。
swfobject.embedSWF
也不返回值,因此最好从代码中删除 jQuery Dollar 函数。如果您只想让代码在匿名函数中运行,请删除
$
并在末尾添加函数调用:第二:
您传递的 FlashVars 变量名称包含连字符,这在 JavaScript 和 ActionScript 中都是非法的。
最后,
removeObjectInIE
(swfobject.removeSWF
的子函数)已在 IE 6、7 和 8 中经过全面测试。由于 IE9 仍处于测试阶段,swfobject 并未正式发布还是支持一下吧但是,我们预计不会出现任何问题。我建议尝试上面提到的编辑,看看是否可以解决您的问题。Two things that immediately caught my eye:
First:
You wrapped your anonymous function (containing the SWFObject code) in a jQuery 'dollar' declaration. The jQuery dollar function "accepts a string containing a CSS selector which is then used to match a set of elements."
Your function doesn't return anything, so it will cause a JavaScript error when jQuery tries to use a null reference as a CSS selector.
swfobject.embedSWF
does not return a value, either, so it would probably be best to drop the jQuery dollar function from your code.If you just wanted your code to run in an anonymous function, drop the
$
and add a function invocation at the end:Second:
You're passing a FlashVars variable name that contains a hyphen, which is illegal in both JavaScript and ActionScript.
Lastly,
removeObjectInIE
(a subfunction ofswfobject.removeSWF
) has been thoroughly tested in IE 6, 7, and 8. Since IE9 is still in beta, swfobject doesn't officially support it yet. However, we don't anticipate any issues. I suggest trying the edits I mention above and see if it clears up your issue.我不知道为什么会发生这种情况,但您可以尝试使用 try/catch 来修复它,
这应该可以避免错误消息。
I don't have an idea, why this happens, but you could try to fix it with a try/catch
This should avoid error messages.