473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2258

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
6185
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" onclick="document.all.someimage.src='someimage.jpg"> but how can i determine whether "someimage.jpg" is loaded? and can i get the download percent of a file? Thanks in advance
9
9350
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 has been loaded? BTW, I'm doing this for several .js files (and I don't always know how many I'll be loading), so I need to check them all. If I...
14
2205
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, right?? I also put a test alert, but alert does not come up if file I'm testing for is loaded in 'main' frame.. thank you.. Frances
4
27992
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 javascript. Within this javascript that runs in test.html, I want to obtain the id of the iframe that loaded test.html in the first place. Is this...
16
2028
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 script is left untouched. However I want to take the script out of the page and have it as a seperate file that can be cached, reducing serving...
6
2550
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 inline in the HTML element attributes. This purging is because the event handlers create the circular memory leak in IE. I am trying to create and...
2
1879
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 after the web page is loaded. 1. Create a new script element (where head is the id of the head tag): var s = document.createElement('script');...
2
1374
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 like to clear them once I am done, so as not to bog down the browser more than needed. I have tried removing the script element, and/or setting the...
6
3288
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 offscreen buffer then fade this over the exisiting page. Can anyone recommend a good way to approach this? thanks
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.