I am injecting a script in my GWT Application
ScriptInjector.fromUrl("js/jquery-1.7.2.min.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>()
{
@Override
public void onSuccess(Void paramT)
{
ScriptInjector.fromUrl("js/viewer-2.2.1/WebViewer.min.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>()
{
@Override
public void onSuccess(Void paramT)
{
ScriptInjector.fromString(getCreateInjection()).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(false).inject();
}....
Now later in the appliation is there a way to remove this script which i injected earlier.
In short, due to how JS works, you can probably do what you are describing and remove the script tag itself, but probably cannot do what you actually mean - the code has been executed, you can't put the toothpaste back in the tube. It it usually possible to remove the script tag, and maybe be possible delete some of the created functions or types that were created, but any code that is already running and interacting with your page is going to stick around until it decided to be done.
Instead, you want to understand the JS script you are using to see if there is a way to ask it to be done, remove any elements it has modified, etc.
--
Both fromUrl
and fromString
variants use an inject()
method, and both methods return a JavaScriptObject
. That object is the actual <script>
tag - you can cast it to Element
and invoke removeFromParent()
on it, and the script tag will be gone - but the side effects from including the script will still be there.
Other options include invoking it in its own <iframe>
and carefully invoking it from the main page, and then removing the iframe - this only serves as simple way to remove all of the exported functions, etc, but will not undo any other side effects. To understand how to do that, you'll need to understand fully what the script is doing - hopefully they have documentation to describe how you can achieve what you are after (or perhaps you can clarify your question further).