Package com.google.gwt.core.client
Class ScriptInjector.FromUrl
java.lang.Object
com.google.gwt.core.client.ScriptInjector.FromUrl
- Enclosing class:
ScriptInjector
Build an injection call for adding a script by URL.
-
Method Summary
Modifier and TypeMethodDescriptioninject()
Injects an external JavaScript reference into the document and optionally calls a callback when it finishes loading.setCallback
(Callback<Void, Exception> callback) Specify a callback to be invoked when the script is loaded or loading encounters an error.setRemoveTag
(boolean removeTag) setWindow
(JavaScriptObject window) This call allows you to specify which DOM window object to install the script tag in.
-
Method Details
-
inject
Injects an external JavaScript reference into the document and optionally calls a callback when it finishes loading.- Returns:
- the script element created for the injection.
-
setCallback
Specify a callback to be invoked when the script is loaded or loading encounters an error.Warning: This class does not control whether or not a URL has already been injected into the document. The client of this class has the responsibility of keeping score of the injected JavaScript files.
Known bugs: This class uses the script tag's
onerror()
callback to attempt to invoke onFailure() if the browser detects a load failure. This is not reliable on all browsers (Doesn't work on IE or Safari 3 or less).On Safari version 3 and prior, the onSuccess() callback may be invoked even when the load of a page fails.
To support failure notification on IE and older browsers, you should check some side effect of the script (such as a defined function) to see if loading the script worked and include timeout logic.
- Parameters:
callback
- callback that gets invoked asynchronously.
-
setRemoveTag
- Parameters:
removeTag
- If true, remove the tag after the script finishes loading. This shrinks the DOM, possibly at the expense of readability if you are debugging javaScript. Default value isfalse
, but this may change in a future release.
-
setWindow
This call allows you to specify which DOM window object to install the script tag in. To install into the Top level window callbuilder.setWindow(ScriptInjector.TOP_WINDOW);
- Parameters:
window
- Specifies which window to install in.
-