On Apr 21, 3:41 pm, cfdvlpr <[EMAIL PROTECTED]> wrote: > Is it possible to remove a script from a page dynamically?
Something like this was just discussed on another mailing list that I read. The answer is something like: A) Remove the script element itself from the DOM. This accomplishes pretty much nothing, since the *code* for the script is still active. B) Imagine that you've saved the names of all global (window) properties before loading the script. So, after you remove the script element, you then need to delete all the properties that didn't exist before; e.g. globals = {}; for (var prop in window) globals[prop] = window[prop]; delete prop; // now you load your script // // use it // // and now you're ready to "unload" it for (var prop in window) { if (typeof globals[prop] == 'undefined') // i.e., defined by your script delete window[prop]; } delete prop; C) Remember that if your script has defined any event handlers that you must revert those as well; otherwise, you'll get errors when, for example, a click event occurs and the handler no longer exists. If you *know* the source of the script you intend to remove, this may be workable; otherwise, it's a big housekeeping problem. -- hj