Removing a loaded script from a page.

D

Daz

Hi everyone.

Is it possible to remove a script that has been added to a page? I have
asked this question before, and was told that it was pretty much
impossible to do, unless of course, I deleted the function. I have had
a little think, and I might have stumbled upon a method of achieving
this, without having to know what functions you actually want to
delete. It might be a method already in practise, so I doubt it's
original, which is why I am asking as I am hoping someone can save me a
lot of time experimenting.

If I dynamically load a script into a hidden iframe, and then delete
the iframe. Would that delete the script that are supposedly in it's
scope? Or would they remain, but be unusable. I would like to use
iframes almost like a namespace, for temporary scripts. Periodically, I
would like to remove the iframe, and replace it with a clean one. Can
anyone tell me off the top of their head if this is likely to work?

Many thanks.

Daz.
 
R

RobG

Daz said:
Hi everyone.

Is it possible to remove a script that has been added to a page?

Yes, but that simplistic answer is unlikely to be useful. I think what
you really want to know is how to release the memory allocated to
functions declared within a script.
I have
asked this question before, and was told that it was pretty much
impossible to do, unless of course, I deleted the function. I have had
a little think, and I might have stumbled upon a method of achieving
this, without having to know what functions you actually want to
delete. It might be a method already in practise, so I doubt it's
original, which is why I am asking as I am hoping someone can save me a
lot of time experimenting.

A simple experiment would take perhaps 10 minutes, exhaustive testing
may never be complete - such is life when scripting browsers.

If I dynamically load a script into a hidden iframe, and then delete
the iframe. Would that delete the script that are supposedly in it's
scope? Or would they remain, but be unusable.

Removing the iFrame and all references to it (including any closures
made to objects within its scope) will make it available for garbage
collection. When, or perhaps if, garbage collection runs, the memory
should be released. Testing will reveal whether or not it is in all
cases.

I would like to use
iframes almost like a namespace, for temporary scripts. Periodically, I
would like to remove the iframe, and replace it with a clean one. Can
anyone tell me off the top of their head if this is likely to work?

The iFrame trick is already used by some for cross-browser consistency
with dynamically loaded scripts, so I imagine it will "work" as you
describe. But why not just add the methods within an object namespace
as been explained previously? Then you can remove an entire namespace
by setting the object (or individual properties) to null.

Surely that is (much) simpler. I can't see that the iFrame trick has
any benefits over the object namespace method.
 
D

Daz

RobG said:
Yes, but that simplistic answer is unlikely to be useful. I think what
you really want to know is how to release the memory allocated to
functions declared within a script.


A simple experiment would take perhaps 10 minutes, exhaustive testing
may never be complete - such is life when scripting browsers.



Removing the iFrame and all references to it (including any closures
made to objects within its scope) will make it available for garbage
collection. When, or perhaps if, garbage collection runs, the memory
should be released. Testing will reveal whether or not it is in all
cases.



The iFrame trick is already used by some for cross-browser consistency
with dynamically loaded scripts, so I imagine it will "work" as you
describe. But why not just add the methods within an object namespace
as been explained previously? Then you can remove an entire namespace
by setting the object (or individual properties) to null.

Surely that is (much) simpler. I can't see that the iFrame trick has
any benefits over the object namespace method.

Simple. Some functions I download would be temporary functions, and
require deleting at set intervals, or maybe after they are run.
However, you make a very good point. I'd be better to add temporary
functions to a temporary namespace, or perhaps manage the scripts
better, and make a list of namespaces that should be deleted. I had
thought of this before, but for some reason didn't think it would be as
'simple' as using iframes as namespaces. Since then, I have had a
moment of clarity.

Thanks for your input Rob.

Daz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top