I'm dynamically changing a script
tag's src attribute using JavaScript.
Problem is, that I'd like to "undo" the previous JavaScript before re-executing it. Any way to do this?
Thanks,
g3
I'm dynamically changing a script
tag's src attribute using JavaScript.
Problem is, that I'd like to "undo" the previous JavaScript before re-executing it. Any way to do this?
Thanks,
g3
I can describe a method I used to achieve a partial undo in a project. Ugly, but might be useful. First, you may need to refactor your script to work from within an iframe, and/or wrap it in a with
statement to give it easy access to some objects in the parent (don't even think of with(opener)
; you'll want something more precise like with({someObject: opener.someObject})
.
When your script runs, it can use the iframe's global scope and DOM freely. Then, instead of reloading the <script>
tag, you overwrite the whole iframe, which will reset everything your script did inside the iframe.