开发者

IE throws 'Unspecified error' when reloading a page with swfobject embedded on it

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?


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:

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

Second: You're passing a FlashVars variable name that contains a hyphen, which is illegal in both JavaScript and ActionScript.

Lastly, removeObjectInIE (a subfunction of swfobject.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.


I don't have an idea, why this happens, but you could try to fix it with a try/catch

try{obj[i] = null;}catch(e){}

This should avoid error messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜