473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Removing a loaded script from a page.

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.

Jan 18 '07 #1
2 2243

Daz wrote:
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.
--
Rob

Jan 18 '07 #2
Daz

RobG wrote:
Daz wrote:
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.
--
Rob
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.

Jan 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Donjuan | last post by:
Hi all I have trouble with tracking whether my image file is loaded. i use DHTML to change my image. HERE is the code: <img name="someimage" src="1.jpg"...
9
by: Ian Richardson | last post by:
If I follow the steps on http://www.dhtmlcentral.com/tutorials/tutorials.asp?id=11 to add .js files to a document on demand, let's say by <body onload="blah();">, how can I reliably tell that it...
14
by: Frances Del Rio | last post by:
if (parent.frames.main.location == 'mediaselect.html') { I have a very simple frameset, name of frame where I'm checking is 'main'... why is this not working? I mean this is correct syntax,...
4
by: christine.nguyen | last post by:
Hello, Here's the deal. I have an html page that contains an iframe. This iframe has an id that is unknown to me. This iframe also has test.html as it's source. Within test.html runs some...
16
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the...
6
by: Peter Michaux | last post by:
Hi, Douglas Crockford mentioned in a video on Yahoo! that before removing an element it is a good idea to purge it's event handlers. I think he was only refering to the event handlers defined...
2
by: www.gerardvignes.com | last post by:
I am using this to load the client JavaScript for a web application when it is selected by the user) via an Ajax connection to the server. I have found only two ways of loading new JavaScript...
2
by: Daz | last post by:
Hi everyone. I would like to know if it's possible to clean up my scripts, or if you will, 'make them biodegradable'. Some of my smaller script will be download to the users browser, but I would...
6
by: Martin Slater | last post by:
Hi all, I'm using a webbrowser control within an application for the UI and want to hide the flicker and redraw when changing pages. Ideally I want to render the new page to a seperate...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.