fabriciocs / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

object not found in fixObjectLeaks() #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Internet Explorer 7
2. Multiple SWFobjects on the page, some video some not.
3. Using swfobject.embedSWF() method for all
3. Navigate away from the page or close the browser

What is the expected output? 
New page is loaded / browser closed without errors

What do you see instead?
Alert dialogue: 
" A runtime error has occured.
  Do you wish to Debug?
  Line 444
  Error: Object doesn't support this property or method " 

What version of the product are you using? On what operating system?
Internet Explorer 7 (IE6 not tested)
SWFObject v2.0 (using un-minified src version for debug purposes)

Please provide any additional information below.
The browser cannot find the HTML objects and throws an error at line 260:
var obj = getElementById(id);
Placing a try-catch around this line prevents the error but I am not sure
if that is the correct solution.

Original issue reported on code.google.com by noisyj...@gmail.com on 25 Apr 2008 at 9:18

GoogleCodeExporter commented 9 years ago
Which version of SWFObject are you using? Did you remove any of the SWFs on your
page? Can you up a test page, please?

Original comment by bobbyvandersluis on 25 Apr 2008 at 9:37

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 25 Apr 2008 at 9:38

GoogleCodeExporter commented 9 years ago
Copied over from issue report 49:

Comment 3 by BStilson, Mar 26, 2008

I'm experiencing this problem with version 2 (not sure what release it is). 
However,
I was able to fix it by moving the "obj" variable above the "win.attachEvent" 
method,
like so:

function fixObjectLeaks(id) {
        if (ua.ie && ua.win && hasPlayerVersion("8.0.0")) {
            var obj = getElementById(id); <-- MOVED HERE
            win.attachEvent("onunload", function () {
                if (obj) {
                    for (var i in obj) {
                        if (typeof obj[i] == "function") {
                            obj[i] = function() {};
                        }
                    }
                    obj.parentNode.removeChild(obj);
                }
            });
        }
    }

Original comment by bobbyvandersluis on 25 Apr 2008 at 10:20

GoogleCodeExporter commented 9 years ago
I can reproduce the issue.

When you remove a dynamically created SWF in IE/Win and browse away from your 
web
page, and then browse back to it, the issue occurs. IE obviously grabs a cached
version of the page. Still I wonder why it throws the error...

Will look for a solution for this, thanks for the feedback.

Original comment by bobbyvandersluis on 25 Apr 2008 at 10:23

GoogleCodeExporter commented 9 years ago
Ok, I cannot reproduce the issue, it appeared that my test case was incorrect.

If you are still hindered by this issue, please add a link to a test page.

Also we are considering to add a formal removeObjectById(id) function to the 
API.

Original comment by bobbyvandersluis on 28 Apr 2008 at 2:13

GoogleCodeExporter commented 9 years ago
Enhancement will be released with SWFObject 2.1

New to the JavaScript API will be the swfobject.removeSWF(objElemIdStr) 
function,
which enables you to safely (and completely in case of IE) remove SWF's from a 
web
page when needed. This functionality has been requested by several JavaScript
developers. It should be used like:

swfobject.addDomLoadEvent(function() {
    swfobject.removeSWF("myContent");
});

to remove a SWF that is represented by an object element with id="myContent".

Static content example:

<!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" lang="en" xml:lang="en">
    <head>
        <title>SWFObject v2.0 sample page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="swfobject.js"></script>
        <script type="text/javascript">
        swfobject.registerObject("myContent", "9.0.0", "expressInstall.swf");
        swfobject.registerObject("myContent2", "9.0.0", "expressInstall.swf");
        swfobject.registerObject("myContent3", "9.0.0", "expressInstall.swf");
        swfobject.addDomLoadEvent(function() {
            swfobject.removeSWF("myContent");
            swfobject.removeSWF("myContent3");
        });
        </script>
    </head>
    <body>
        <div>   
            <object id="myContent" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="300" height="120">
                <param name="movie" value="test.swf" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="test.swf" width="300"
height="120">
                <!--<![endif]-->
                <div>
                    <h1>Alternative content</h1>
                    <p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
                </div>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
            <object id="myContent2" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="300" height="120">
                <param name="movie" value="test.swf" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="test.swf" width="300"
height="120">
                <!--<![endif]-->
                <div>
                    <h1>Alternative content</h1>
                    <p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
                </div>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
            <object id="myContent3" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="300" height="120">
                <param name="movie" value="test.swf" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="test.swf" width="300"
height="120">
                <!--<![endif]-->
                <div>
                    <h1>Alternative content</h1>
                    <p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
                </div>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>
    </body>
</html>

Dynamic content example:
<!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" lang="en" xml:lang="en">
    <head>
        <title>SWFObject v2.0 dynamic embed sample page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="swfobject.js"></script>
        <script type="text/javascript">
        swfobject.embedSWF("test.swf", "myContent", "300", "120", "9.0.0",
"expressInstall.swf");
        swfobject.embedSWF("test.swf", "myContent2", "300", "120", "9.0.0",
"expressInstall.swf");
        swfobject.embedSWF("test.swf", "myContent3", "300", "120", "9.0.0",
"expressInstall.swf");
        swfobject.addDomLoadEvent(function() {
            swfobject.removeSWF("myContent");
            swfobject.removeSWF("myContent3");
        });
        </script>
    </head>
    <body>
        <div id="myContent">
            <h1>Alternative content</h1>
            <p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
        </div>
        <div id="myContent3">
            <h1>Alternative content</h1>
            <p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
        </div>
        <div id="myContent2">
            <h1>Alternative content</h1>
            <p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
        </div>
    </body>
</html>

If you would like to beta test this new method, please download SWFObject 2.1 
beta2:
http://code.google.com/p/swfobject/source/browse/trunk/swfobject/src/swfobject.j
s?r=153

Original comment by bobbyvandersluis on 28 Apr 2008 at 3:20

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 28 Apr 2008 at 3:40

GoogleCodeExporter commented 9 years ago
Thanks for your action on this. Unfortunately I don't have access to a public 
server
so I can't link to a test page. I will try to post a simplified version of my 
code
instead. My solution was to add in a try-catch

function fixObjectLeaks(id) {
    if (ua.ie && ua.win && hasPlayerVersion("8.0.0")) {
        win.attachEvent("onunload", function () {
        // added in try-catch to allow code to continue
            try {
                var obj = getElementById(id);
            } catch (e) {
                // no object with Id = id exists. 
            }

            if (obj) {
                for (var i in obj) {
                    if (typeof obj[i] == "function") {
                        obj[i] = function() {};
                    }
                }
                obj.parentNode.removeChild(obj);
            }
        });
    }
}

Original comment by noisyj...@gmail.com on 29 Apr 2008 at 8:18

GoogleCodeExporter commented 9 years ago
Great, it will be good to have a simple test case which shows the context of 
your
issue. While creating my testcases I found that it is pretty easy to remove 
SWFs the
wrong way, hence the introduction of the swfobject.removeSWF() method to do 
unify
this effort.

Original comment by bobbyvandersluis on 29 Apr 2008 at 9:06

GoogleCodeExporter commented 9 years ago
Copied from http://code.google.com/p/swfobject/issues/detail?id=83

Reported by mayerbe...@gmx.net, Yesterday (27 hours ago)

What steps will reproduce the problem?
every time we close a ie browser window which uses swfobject 2.0.

What is the expected output? What do you see instead?
close without a js error.

What version of the product are you using? On what operating system?
swfobject 2.0, ie6 or 7, windows xp

Please provide any additional information below.
i debugged the real not compressed source and saw that the swfobject
function getElementById call the doc.getElementById function which, in this
case, not exists on the doc object.
so we could solve this error by changing the function on line 444 which
causes the error from this:
function getElementById(id) {
    return doc.getElementById(id);
}
to this
function getElementById(id) {
    if (doc.getElementById)
        return doc.getElementById(id);
    else
        return null;
}

Original comment by bobbyvandersluis on 1 May 2008 at 12:50

GoogleCodeExporter commented 9 years ago
Re comment 10:

Did you remove a SWF from your page? Do you have a test page that can help us
reproduce the issue?

I found that part of the problem is that in IE it is complex to completely 
remove a
SWF, so most users do it the wrong way, resulting in errors.

Will look into how to make the library more robust in these kind of situations.

Original comment by bobbyvandersluis on 1 May 2008 at 12:55

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 5 May 2008 at 7:20

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 6 Jun 2008 at 3:45

GoogleCodeExporter commented 9 years ago
I also met the same problem when I used mootools together with swfobject. And I 
think
it maybe due to the Garbage.empty method in mootools. 

The version of mootools is 1.11 and swfobject is 2.0

Original comment by wangshou...@gmail.com on 13 Jun 2008 at 8:35

GoogleCodeExporter commented 9 years ago
I have this same problem, also in conjunction with mootools. It is exactly as
described, a js error occurs when the url changes or the browser is closed, in 
my
case it's on line 5:
return K.getElementById(q) in function C(q)
using SWFObject 2.1

Original comment by shyguyNC...@gmail.com on 15 Jun 2008 at 5:58

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 15 Jun 2008 at 9:28

GoogleCodeExporter commented 9 years ago
@wangshoutao: you'd better upgrade to SWFObject 2.1 and Mootools 1.2

@shyguyNCDnB: we'll take a look at it

Original comment by bobbyvandersluis on 16 Jun 2008 at 8:58

GoogleCodeExporter commented 9 years ago
@shyguyNCDnB: could you do us a favor and please download the uncompressed 
swfobject
2.1 beta 7 version, and update the following function:

function getElementById(id) { ... }

to:

function getElementById(id) {
    try {
        return doc.getElementById(id);
    }
    catch(e) {
        return undefined;
    }
}

and let us know if this solves your issue?

Original comment by bobbyvandersluis on 16 Jun 2008 at 9:07

GoogleCodeExporter commented 9 years ago
Correction, please replace it for the following function:

function getElementById(id) {
    try {
        return doc.getElementById(id);
    }
    catch(e) {
        return null;
    }
}

Original comment by bobbyvandersluis on 16 Jun 2008 at 9:45

GoogleCodeExporter commented 9 years ago
@shyguyNCDnB: also, I cannot reproduce the issue myself, so could you please 
link to
a test page?

Original comment by bobbyvandersluis on 17 Jun 2008 at 7:10

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 18 Jun 2008 at 3:29

GoogleCodeExporter commented 9 years ago
sorry, i should have been back to this thread sooner.
i have updated swfobject.js with a try catch block, but now I get an entirely
different set of errors:
for every flash movie in the page multiplied by number of flash methods exposed 
with
ExternalInterface.addCallback, I get a separate js error when the URL changes 
or the
window is closed:

Line 0: Object doesn't support this property or method'

tracing that with MS Script Debugger yields this as the offending line:
__flash__removeCallback(document.getElementById([name of object]), "[name of 
flash
method exposed with ExternalInterface.addCallback]");

I suspect that it may be a conflict with mootools, as I can remove the mootools
library and it clears things up .. unfortunately, getting rid of mootools in 
not an
option for me, so I have to figure out how to make it play nice with swfobject.

here's a link to a problem page:

http://www.capefearcoppershop.com/webassign/core_pad_1.0/alpha/mathPad.html

open that in IE, then close it ... you should get the errors

any insight is greatly appreciated, have been trying to fix this for weeks 
(literally)

Original comment by shyguyNC...@gmail.com on 30 Jun 2008 at 7:13

GoogleCodeExporter commented 9 years ago
Adobe External interface itself attaches a set of JavaScript functions to your 
object
elements as soon as you implement it. The returned error comes from this 
library. I
think that the issue is that Mootools too aggressively removes elements, 
breaking
Flash functionality in IE. 

A possible solution. Call removeSWF (for IE only) for all your SWFs before 
Mootools
does its removal routine, e.g. you could try to attach an event onBeforeUnload. 
Also,
maybe you could write your custom function to remove elements, instead of using
Mootools functions (or maybe wrap them in your own functions), so you can use
swfobject.removeSWF in tandem with it. 

Original comment by bobbyvandersluis on 1 Jul 2008 at 8:55

GoogleCodeExporter commented 9 years ago
In this case, Mootools is a little bit too entwined in other (non Flash related)
functionality to get rid of it (plus I don't have that kind of pull on the dev 
team
:) ). I'm going to try using removeSWF(), somehow I missed that it had been 
added to
the swfobject library. Thanks for the suggestion!

Original comment by shyguyNC...@gmail.com on 1 Jul 2008 at 1:55

GoogleCodeExporter commented 9 years ago
Just reporting back, calling removeSWF() on all Flash objects onBeforeUnload 
cleared
up all the IE issues ... thanks for the help!

Original comment by shyguyNC...@gmail.com on 3 Jul 2008 at 4:49